When you say "loop all tree view nodes", I assume you mean you want to
iterate through the entire tree. You need recursion for this.
Public Sub Iterate ()
Iterate_Aux ( theTree.Nodes ( 0 ) )
End Sub
' --- This is a prefix iteration
Public Sub Iterate_Aux ( byref theNode as TreeViewNode )
DoSomethingWithTheNode (theNode)
' Now do something with the children of this node
for each theChildNode as TreeViewNode in theNode.Nodes
Iterate_Aux ( theChildNode )
next
End Sub
' --- This is a postfix iteration
Public Sub Iterate_Aux ( byref theNode as TreeViewNode )
' Do something with the children first
for each theChildNode as TreeViewNode in theNode.Nodes
Iterate_Aux ( theChildNode )
next
' Do something with the node.
DoSomethingWithTheNode (theNode)
End Sub
"J.B." <an*******@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
Hi,
Can anybody show me how to loop all treeview nodes ini vb.net. I've been
working on this for days but still no result. I got a sample code in vb 6.0, this one works.
Private Sub SaveNested()
Dim TNode As Node
Set TNode = TreeView1.Nodes(1).Root
While Not TNode Is Nothing
If TNode.children > 0 Then
AddChildNodes(TNode)
End If
Set TNode = TNode.Next
Wend
End Sub
Private Sub AddChildNodes(ByVal TNode As Node)
Dim childNode As Node
Dim i As Integer
Set childNode = TNode.Child
For i = 0 To TNode.children - 1
If childNode.children > 0 Then
AddChildNodes(childNode)
End If
Set childNode = childNode.Next
Next
End Sub
I tried to rewrite the code in vb.net, but then stuck in using
treeview(.net) properties. Could advice me how to write this in vb.net. Thanks
Yanto