3个回答
展开全部
//建立一棵以设备ID为名称的树
private void createTree(TreeView mytree)
{
#region 建立一棵以数字建立的树
string SQLSTR = null;
SQLSTR = SQL_CreatTree();
MyDataBase db = new MyDataBase();
db.dbServer = txt_Server.Text ;
db.Open();
DataSet ds = db.ExecuteSql(SQLSTR);
db.Close();
Draw_StorageDev std = new Draw_StorageDev();
//////将数据写入Tree
mytree.Nodes.Clear();
TreeNode rootNode = treeView1.Nodes.Add("设备");
rootNode.ImageIndex = 2;
rootNode.SelectedImageIndex = 2;
rootNode.Tag = 0;
//通过sql计算第二层的树
TreeNode secondNode = new TreeNode();
SQLSTR = "select * from afc_group ";
DataSet ds_SECOND = db.ExecuteSql(SQLSTR);
for (int i = 0; i < ds_SECOND.Tables[0].Rows.Count; i++)
{
secondNode = new TreeNode();
secondNode.Tag =ds_SECOND.Tables[0].Rows[i]["GROUP_ID"];
secondNode.Text =Convert.ToString ( ds_SECOND.Tables[0].Rows[i]["GROUP_NAME"]);
secondNode.ImageIndex = 2;
secondNode.SelectedImageIndex =2;
rootNode.Nodes.Add(secondNode);
}
//子节点赋值
TreeNode childNode = new TreeNode();
TreeNode subNode=new TreeNode ();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)//遍历所有用户
{
if (ds != null)
{
std.SLEID = (Int32)(ds.Tables[0].Rows[i]["SLEID"]);
std.SLEName = Convert.ToString(ds.Tables[0].Rows[i]["SLEName"]);
std.SLEStation = Convert.ToInt16(ds.Tables[0].Rows[i]["SLEstation"]);
std.SLE_Group = (Int32)(ds.Tables[0].Rows[i]["sle_group"]);
}
childNode = new TreeNode();
//子节点赋值
childNode.Text = std.SLEName;
childNode.Tag = std.SLEID;
if (std.SLEStation == 1 || std.SLEStation == 2) //设备类型
{
childNode.ImageIndex = 1;//人流量检测
childNode.SelectedImageIndex = 1;
}
else
{
childNode.ImageIndex = 0;//TVM检测
childNode.SelectedImageIndex = 0;
}
//通过检索方式找到节点
for (int j = 0; j < treeView1.Nodes[0].Nodes.Count; j++)
{
subNode = treeView1.Nodes[0].Nodes[j];
if ((int)subNode.Tag == (int)std.SLE_Group)
{
subNode.Nodes.Add(childNode);
//通过增加子节点的值给父节点
//通过判断父节点的ImageIndex值,写入子节点值
if (subNode.ImageIndex != 2)
{
if (subNode.ImageIndex != childNode.ImageIndex)
{
subNode.ImageIndex = 2;
}
}
else
{
subNode.ImageIndex = childNode.ImageIndex;
continue;
}
}
}
}
mytree.Nodes[0].Expand();
#endregion
}
private void createTree(TreeView mytree)
{
#region 建立一棵以数字建立的树
string SQLSTR = null;
SQLSTR = SQL_CreatTree();
MyDataBase db = new MyDataBase();
db.dbServer = txt_Server.Text ;
db.Open();
DataSet ds = db.ExecuteSql(SQLSTR);
db.Close();
Draw_StorageDev std = new Draw_StorageDev();
//////将数据写入Tree
mytree.Nodes.Clear();
TreeNode rootNode = treeView1.Nodes.Add("设备");
rootNode.ImageIndex = 2;
rootNode.SelectedImageIndex = 2;
rootNode.Tag = 0;
//通过sql计算第二层的树
TreeNode secondNode = new TreeNode();
SQLSTR = "select * from afc_group ";
DataSet ds_SECOND = db.ExecuteSql(SQLSTR);
for (int i = 0; i < ds_SECOND.Tables[0].Rows.Count; i++)
{
secondNode = new TreeNode();
secondNode.Tag =ds_SECOND.Tables[0].Rows[i]["GROUP_ID"];
secondNode.Text =Convert.ToString ( ds_SECOND.Tables[0].Rows[i]["GROUP_NAME"]);
secondNode.ImageIndex = 2;
secondNode.SelectedImageIndex =2;
rootNode.Nodes.Add(secondNode);
}
//子节点赋值
TreeNode childNode = new TreeNode();
TreeNode subNode=new TreeNode ();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)//遍历所有用户
{
if (ds != null)
{
std.SLEID = (Int32)(ds.Tables[0].Rows[i]["SLEID"]);
std.SLEName = Convert.ToString(ds.Tables[0].Rows[i]["SLEName"]);
std.SLEStation = Convert.ToInt16(ds.Tables[0].Rows[i]["SLEstation"]);
std.SLE_Group = (Int32)(ds.Tables[0].Rows[i]["sle_group"]);
}
childNode = new TreeNode();
//子节点赋值
childNode.Text = std.SLEName;
childNode.Tag = std.SLEID;
if (std.SLEStation == 1 || std.SLEStation == 2) //设备类型
{
childNode.ImageIndex = 1;//人流量检测
childNode.SelectedImageIndex = 1;
}
else
{
childNode.ImageIndex = 0;//TVM检测
childNode.SelectedImageIndex = 0;
}
//通过检索方式找到节点
for (int j = 0; j < treeView1.Nodes[0].Nodes.Count; j++)
{
subNode = treeView1.Nodes[0].Nodes[j];
if ((int)subNode.Tag == (int)std.SLE_Group)
{
subNode.Nodes.Add(childNode);
//通过增加子节点的值给父节点
//通过判断父节点的ImageIndex值,写入子节点值
if (subNode.ImageIndex != 2)
{
if (subNode.ImageIndex != childNode.ImageIndex)
{
subNode.ImageIndex = 2;
}
}
else
{
subNode.ImageIndex = childNode.ImageIndex;
continue;
}
}
}
}
mytree.Nodes[0].Expand();
#endregion
}
展开全部
我的空间http://user.qzone.qq.com/174900771/infocenter
C# TreeView的节点全部操作(复选框取值,赋值)
这里有你要的,只是从数据库中读取是相当容易的,表结构设计好,然后读取出来,用tViewMenu.Nodes.AddRange方法或者另一种即可
C# TreeView的节点全部操作(复选框取值,赋值)
这里有你要的,只是从数据库中读取是相当容易的,表结构设计好,然后读取出来,用tViewMenu.Nodes.AddRange方法或者另一种即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-07-21
展开全部
不会
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询