How To Add Root Node In Tree View Dynamically Using Asp.net

前端 未结 3 1022
小鲜肉
小鲜肉 2021-01-23 17:53

I Want To Bind DataTable To TreeView.I Have Written Following Code.Its Working Currently,Means It Displays All Data Of DataTable But No Root Node.

 List

        
3条回答
  •  礼貌的吻别
    2021-01-23 18:08

    // Suppress repainting the TreeView until all the objects have been created.
    treeView1.BeginUpdate();
    
    // Clear the TreeView each time the method is called.
    treeView1.Nodes.Clear();
    
    // create root node
    TreeNode root = new TreeNode("Root");
    
    // loop and add all child nodes to root node
    foreach (DataRow r in dt.Rows)
    {
        // create child node 
        // add to root node 
         root.Nodes.Add(child);
    }
    
    // add root node to tree view
    treeView1.Nodes.Add(root);
    
    // Begin repainting the TreeView.
    treeView1.EndUpdate();
    

提交回复
热议问题