日期:2014-05-19  浏览次数:20377 次

treeview控件动态怎么样添加节点
在treeview中怎么样动太将一个根节点数组和一个子节点数组添加进去?
最好给个列子   ~~~~~~~~~~~~~~~在线等   谢谢

------解决方案--------------------
string[] ary = new string[] { "1 ", "2 ", "3 ", "4 " }; for (int i = 0; i < ary.Length; i++) { TreeNode node = new TreeNode(); node.Text = ary[i]; this.TreeView1.Nodes.Add(node); }
------解决方案--------------------
string[] aryParent = new string[] { "1 ", "2 ", "3 "};
string[] arySub1 = new string[] { "101 ", "102 ", "103 "};
string[] arySub2 = new string[] { "201 ", "202 ", "203 "};

下面函数的TreeNodeCollection参数:

根节点
TreeView1.Nodes
节点TreeNodei的子节点:
TreeNodei.ChildNodes

// 用数组填充树
public void FillTree(TreeNodeCollection tns, params string[] ary)
{
TreeNode tn = null;
foreach (string s in ary)
{
tn = new TreeNode();
tn.Text = s;
tns.Add(tn);
}
}