[RESOLVED] Building a treeview VB.Net 2003
Hi,
I have a treeview built, and it works just like I want it. However, I have to "prime" it with the first level of nodes. After that, I go through each first level node and add nodes to it, and add nodes to its nodes, and .... all the way down recursively. This recursive function, AddNodes, receives a node as its input. So, right now its like this:
BuildTree()
GrabFirstLevelNodes()
for each node in tree
AddNodes(node)
End Sub
Is there any way around this, or is my code just going to have to have this ugly GrabFirstLevelNodes sub? I tried to send the tree itself as a node (figured it was worth a shot), but it isn't the right type.
Any ideas?
Thanks
Re: Building a treeview VB.Net 2003
Your recursive function should take a TreeNodeCollection as an argument. The Nodes property of the TreeView itself is a TreeNodeCollection, as is the Nodes property of each node. That means that you can pass the Nodes property of the tree itself to the first call and then for each recursive call you pass the Nodes property of a node, e.g.
VB Code:
PopulateNodeCollection(myTreeView.Nodes)
VB Code:
Public Sub PopulateNodeCollection(ByVal nodes As TreeNodeCollection)
'Add nodes here.
For Each node As TreeNode In nodes
PopulateNodeCollection(node.Nodes)
Next node
End Sub
That's a very simple and incomplete example but you get the idea.