Loop Treeview Nodes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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).Roo

While Not TNode Is Nothin
If TNode.children > 0 The
AddChildNodes(TNode
End I
Set TNode = TNode.Nex
Wend
End Su

Private Sub AddChildNodes(ByVal TNode As Node
Dim childNode As Nod
Dim i As Intege
Set childNode = TNode.Chil

For i = 0 To TNode.children - 1
If childNode.children > 0 The
AddChildNodes(childNode
End I
Set childNode = childNode.Nex
Nex
End Su

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
Thank

Yant
 
i am working w the infragistics tree but it should be the same
and i'm not rally sure this is wat you want (a loop not doing anithing
special?)

private sub looplvl1()
Dim TNode As Node
for each tnode in tree.nodes
messagebox.show(tnode.text)
loopother(tnode)
next
end sub

private sub loopother(PNode As Node )
Dim TNode As Node
for each tnode in Pnode.nodes
messagebox.show(tnode.text)

next

end sub

J.B. said:
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.
 
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. said:
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.
 
* "=?Utf-8?B?Si5CLg==?= said:
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.

\\\
RecurseNodes(Me.TreeView1.Nodes)
..
..
..

Private Function RecurseNodes(ByVal Node As TreeNodeCollection)
For Each tn As TreeNode In Node
If tn.Text = "Foo" Then
Me.TreeView1.SelectedNode = tn
Return
End If
RecurseNodes(tn.Nodes)
Next tn
End Function
///
 
Thanks for all of the responds. It helps a lot

Well, the loop was for a start. I need to save treeview's data into xml file. I'm still working on it

Yant

----- EricJ wrote: ----


i am working w the infragistics tree but it should be the sam
and i'm not rally sure this is wat you want (a loop not doing anithin
special?

private sub looplvl1(
Dim TNode As Nod
for each tnode in tree.node
messagebox.show(tnode.text
loopother(tnode
nex
end su

private sub loopother(PNode As Node
Dim TNode As Nod
for each tnode in Pnode.node
messagebox.show(tnode.text

nex

end su
 
Back
Top