adding a node to a parent node in a tree view

B

Brian Henry

If i already have a tree view created, and want to add another new node to
it, how would i do so? Is there a way to throught tags or anything? like i
have this

RootNode
|
+-- Child 1
+-- Child 2

and i want to add a child node to child 1 how would i refrence it and add a
new one to it after the list was already made? thanks (each node is getting
a name and a tag during the initial creation)
 
I

IbrahimMalluf

Hello Brian

To add children to a node you have to get a reference to the node you want
to add children to then use the Nodes.Add methof of the node. The code
below adds three levels of nodes using for-next loops. It should provide
youy with a demonstration of how to populate a treeview


Dim TopNode As TreeNode

Dim SecondNode As TreeNode

Dim ThirdNode As TreeNode

With Me.TreeView1

For MyCount1 As Integer = 0 To 5

'adds top level node

TopNode = .Nodes.Add("TopNode" & MyCount1)

For MyCount2 As Integer = 0 To 5

'adds second level node

SecondNode = TopNode.Nodes.Add("SecondLevelNode" & MyCount2)

For MyCount3 As Integer = 0 To 5

'adds third level node

SecondNode.Nodes.Add("ThirdLevelNode" & MyCount3)

Next

Next

Next

End With




--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx
 
B

Brian Henry

yes that I know, but if I am dynamically adding new nodes after it has been
initially built how would i find a node in the tree that I am looking for
and preform an add to its node colletion?
 
W

Webster

You can recursively iterate through the nodes (starting at the root), and
then just find that matching tag or text or whatever.

node find (string tofind, node root)
if root has children
return find(tofind, root.nodes(0))
else
if root.tag = tofind then
return root
end if
end if
end function

something like that pseudo code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top