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
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")
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
Re: how to add a node in a specific node
oh actually the code is not working :-(
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