469,626 Members | 883 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Loop Treeview Nodes

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

Nov 20 '05 #1
4 12346

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." <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

Nov 20 '05 #2
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

Nov 20 '05 #3
* "=?Utf-8?B?Si5CLg==?=" <an*******@discussions.microsoft.com> scripsit:
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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
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

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by alanrn | last post: by
3 posts views Thread by Steve Richter | last post: by
4 posts views Thread by Jeroen Ceuppens | last post: by
5 posts views Thread by Mark Goldin | last post: by
4 posts views Thread by Ian Powell | last post: by
14 posts views Thread by Mr.D | last post: by
1 post views Thread by | last post: by
1 post views Thread by doemon | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.