有人知道如在 

-B 
--C 
---D 
----E 
-----..... 
这样的tree下,添加个指定位置的子节点怎么写嘛?比如我要添加个 和B同级的节点,后台CS代码怎么写?

解决方案 »

  1.   

    找到b的父节点,给这个父节点添加子节点。
    1.找到父节点,方法遍历查找
    2.添加子节点,node.ChildNode.Add()方法
      

  2.   


    treeView1.Nodes[0].Nodes.Insert(1, "b");
      

  3.   

    TreeNode root = new TreeNode();
                    root.Text = ds.Tables[0].Rows[2][2].ToString();
                    root.Target = ds.Tables[0].Rows[2][0].ToString();
                    this.TreeView1.Nodes[1].ChildNodes.Add(root);
    我这样写,他总是提示我超出数组,可明明就已经存在了
      

  4.   

     如果连接的数据库,要指定父类别ID,本身ID,这样好控制
      

  5.   

    this.TreeView1.Nodes[1].ChildNodes.Add(root); 
    -------------------------------------------
    this.TreeView1.Nodes.Add(root); 当前Nodes为空,[1]肯定会下标越界的。
      

  6.   

    但是在后台,我再load里已经绑定过一次了啊
      

  7.   

    this.TreeView1.Nodes[1]  跟踪看看这个对象有没内容就完事了