I have a function in my application that builds a tree view. It
populates the tree view with parent nodes. The parent nodes are the
drives on my pc. When the user selects the node, I have a function
that takes the tag of the node and passes it to the Directory method.
A node is then created under the selected node with folder names.
I now have a tree view with parent and children nodes. Now, I would
like to loop through all the nodes in the tree view as it is now. For
exampleůthe Root Parent nodes are drives A, C, D, E, and F. When the
user selects F, then children nodes are addedůlikeůMovie Folder, Doc
Folder, File Folderů.whatever folders that are under F. I would like
to loop through all the nodes and highlight them as the loop goes
along.
I figured I could get a node count in the beginning and simply
interate through the node index. In my example, the node count was
something like 15. so I figured I could just do something like thisů
Dim nodeCount As Intger = TreeView.GetNodeCount(True)
Dim inc As Integer = 0
Dim nodeTag As String
Do While Not(inc > nodeCount)
nodeTag = TreeView.Nodes.Item(inc).Tag
ĹHIGHLIGHT THIS NODE AND DO SOMETHING WITH NODE
inc = inc + 1
Loop
The problem I am seeing is that the node count is 15, because I added
nodes to the tree from a nodes selection event, but when I go to index
6, I get a message like "Index is out of range." I figured it should
be in range because the nodes exist.
Do I have to do something special to add the nodes to the nodes
collection? Aren't the nodes automatically added to the node
collections when they are created? Why would child nodes be out of
range?
I don't know how I can simply loop through all the nodes, could
someone please, please, please help me out with this?
Thank you all.
\\\
Private Sub RecurseNodes(ByVal col As TreeNodeCollection)
For Each tn As TreeNode In col
MsgBox(tn.Text)
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes)
End If
Next tn
End Sub
Private Sub Test()
RecurseNodes(Me.TreeView1.Nodes)
End Sub
///
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Bye the way….do have any ideas on how I might be able to highlight the
current node as the loop executes?
Thanks once again for the prompt assistance!!!!!
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com/g/