I am attempting to find a particular node in a Treeview so that I can add nodes to that particular node. But when I try to loop through the nodes I am only getting the Root node. Here is the code I am using:
VB Code:
Private Sub AddNodes() Dim tnode As TreeNode 'Treeview Node Dim a As Integer 'Counter tnode = Me.TreeView1.Nodes.Add("Root Node", "Root", 14) Selectednode = tnode AddChild(Selectednode, "Child 1", 1) AddChild(Selectednode, "Child 2", 2) AddChild(Selectednode, "Child 3", 3) AddChild(Selectednode, "Child 4", 4) AddChild(Selectednode, "Child 5", 5) AddChild(Selectednode, "Child 6", 6) a = 0 With TreeView1 For Each tnode In .Nodes '<==The root node is the only node in collection With .Nodes If .Item(a).Text = "Child 3" Then 'Add Gr Child Node to Child 3 Selectednode = .Item(a) AddChild(Selectednode, "Grand Child 1", 12) AddChild(Selectednode, "Grand Child 2", 13) Exit For 'Exit Loop if Found End If End With a = a + 1 'Increment Counter Next End With End Sub
Any ideas?




Reply With Quote