Community discussion forum

adding node to treeView control

  • 2 years ago
    Hello there,
    How can i add a node in a certian place in a treeView control?

    Thanks ahead


  • 2 years ago

    There are a few ways, but it's wise to explore the easy ones first:

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.treenodecollection.insert.aspx

    You may also like to explore the Find method:

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.treenodecollection.find.aspx

    It lets you find a node which you can then add further nodes to using the Add method.

    Also, there's an example over here:

    http://www.c-sharpcorner.com/UploadFile/scottlysle/TreeviewBasics04152007195731PM/TreeviewBasics.aspx

    HTH

     

  • 2 years ago

    There are a few ways to do this

    Basic

    treenode.Nodes.Add("Add")
    treenode.Nodes.Add("Delete")

    Bit More Advanced

    foreach { DataRow drStuff in dtStuff.Rows)

    {
       TreeNode newNode = new TreeNode()
       newNode.Text = drStuff["MyField"].ToString
       newNode.Tag = drFood;
       treeNode.Nodes.Add(newNode);

    }

    Treeview Structure

    TreeNode node;

    node = treeNode.Nodes.Add("Level1") ;
    node.Nodes.Add("Level2");
    node.NodeslAdd("Another Level2");
     



    node = treeNode.Nodes.Add("Another Level1") ;
    node.Nodes.Add("Another Level2");
    node.NodeslAdd("Another Another Level2");




    Frank

     

     

     





Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback