|
-
Nov 23rd, 2002, 06:44 AM
#1
Thread Starter
New Member
how to recursively view all child nodes in a treeview
Hi,
I'm trying to recursively go through all of the child nodes in a tree view upon clicking a button but I'm stuck. Currently, the code below only works for the top nodes in my treeview but I want it to go through each of these nodes' children, and their children and so on.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim child As TreeNode
Dim fullpath As String
For Each child In TreeView1.Nodes
fullpath = child.FullPath
Next
End Sub
If anyone can suggest a solution, or where I'm going wrong I'd be grateful.
Thanks,
Karl
-
Nov 23rd, 2002, 07:33 AM
#2
Registered User
Maybe there is an easier way but this code displays a Messagebox with the full path for each node in a treeview. I had a TreView1 with a couple of nodes and a Button1 control:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim node As TreeNode
For Each node In TreeView1.Nodes
MsgBox(node.FullPath)
GoThroughNodes(node)
Next
End Sub
Private Sub GoThroughNodes(ByVal node As TreeNode)
Dim node2 As TreeNode
For Each node2 In node.Nodes
If node2.GetNodeCount(False) = 0 Then
MsgBox(node2.FullPath)
Else
MsgBox(node2.FullPath)
GoThroughNodes(node2)
End If
Next
End Sub
I recursively call the GoThroughNodes procedure to go into each nodes children.
/Leyan
-
Nov 23rd, 2002, 08:38 AM
#3
Thread Starter
New Member
Thanks
Thanks again Leyan for your help.
That works perfectly!
Karl
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|