472,378 Members | 1,236 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

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 12669

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: alanrn | last post by:
I am using a TreeView to display the hierarchy of a strongly-typed collection (inherited from CollectionBase). The order of the nodes in the TreeView is strictly tied to the order in which they...
3
by: Steve Richter | last post by:
in windows explorer, the nodes immed under the "my computer" root node appear with a minimum of indenting ( the +/- square is directly underneath the root node ). In the .NET TreeView control the...
4
by: Jeroen Ceuppens | last post by:
Hi, I want to make something that adds a TreeNode to the end of TreeView, that TreeView Looks like + Level 1 + Level 2 + Level 3 - Level last
5
by: Mark Goldin | last post by:
Anybody can shart some working samples of using that control on Windows form? Thanks
4
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
1
by: | last post by:
What's the best way to create new nodes on a treeview 2.0 and save them to an xml file? Thanks, Victor
0
by: apenly | last post by:
Hi all- I'm trying to Render a TreeView in a custom control, but I'm receiving a NullReferenceException at runtime. If I put the TreeView on the page it works fine, but as soon as I try to...
1
by: doemon | last post by:
Hi, I'm working on a pagination control and I need to dynamically rerender a treeview to display the next set of nodes depending on which page we're on. For example, page 1 will dispaly only...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.