Results 1 to 5 of 5

Thread: how to add a node in a specific node

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    how to add a node in a specific node

    Hi

    I am using a form with 2 buttons and one treeview
    in the first button , I can add a node with this code

    dim c as treeNode
    c=TreeView1.Nodes.Add("hello")

    in the second button i can add a node but only in the last node
    c.nodes.add("World")

    My question is how to add a node in the third node or a specific node of the treeView

    Thank you

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: how to add a node in a specific node

    Instead of just specifying the text of the node when you add it to the tree, give each node a unique key. That way you can use the Key to reference the specific node.
    Code:
    TreeView1.Nodes.Add("hello", "Hello World") 'the first value is the key
    TreeView1.Nodes("hello").Add("newNode", "Child node")

  3. #3

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    Re: how to add a node in a specific node

    Ok , how can i know the the name of a specific node
    for example the 3rd node
    Thank you

  4. #4

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    Re: how to add a node in a specific node

    oh actually the code is not working :-(

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: how to add a node in a specific node

    Oh sorry, I wrote the code directly in the post. This is what it should look like.
    Code:
    TreeView1.Nodes.Add("hello", "Hello World") 'the first value is the key
    TreeView1.Nodes("hello").Nodes.Add("newNode", "Child node")
    Or if you think it's easier to read:
    Code:
    TreeView1.Nodes.Add("hello", "Hello World") 'the first value is the key
    Dim node As TreeNode = TreeView1.Nodes("hello")
    node.Nodes.Add("newNode", "Child node")
    You can also reference the nodes by index
    Code:
    Dim node As TreeNode = TreeView1.Nodes(0) 'the first node

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width