473,881 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(T Node
End I
Set TNode = TNode.Nex
Wend
End Su

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

For i = 0 To TNode.children - 1
If childNode.child ren > 0 The
AddChildNodes(c hildNode
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 12856

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*******@disc ussions.microso ft.com> wrote in message
news:8B******** *************** ***********@mic rosoft.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(T Node)
End If
Set TNode = TNode.Next
Wend
End Sub

Private Sub AddChildNodes(B yVal TNode As Node)
Dim childNode As Node
Dim i As Integer
Set childNode = TNode.Child

For i = 0 To TNode.children - 1
If childNode.child ren > 0 Then
AddChildNodes(c hildNode)
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 )

DoSomethingWith TheNode (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.

DoSomethingWith TheNode (theNode)

End Sub

"J.B." <an*******@disc ussions.microso ft.com> wrote in message
news:8B******** *************** ***********@mic rosoft.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(T Node)
End If
Set TNode = TNode.Next
Wend
End Sub

Private Sub AddChildNodes(B yVal TNode As Node)
Dim childNode As Node
Dim i As Integer
Set childNode = TNode.Child

For i = 0 To TNode.children - 1
If childNode.child ren > 0 Then
AddChildNodes(c hildNode)
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*******@disc ussions.microso ft.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.Node s)
..
..
..

Private Function RecurseNodes(By Val Node As TreeNodeCollect ion)
For Each tn As TreeNode In Node
If tn.Text = "Foo" Then
Me.TreeView1.Se lectedNode = 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
1285
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 appear in the underlying collection. However, the user must be able to reorder certain items in the collection--and, hence, the TreeView. I have created a context-sensitive menu that allows the user to move an item in the collection either up or...
3
8847
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 indent is shifted one more indent level to the right, wasting valuable horizontal space. How can I instruct TreeView to indent from the root node the same way as windows explorer does? thanks,
4
5269
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
8128
by: Mark Goldin | last post by:
Anybody can shart some working samples of using that control on Windows form? Thanks
4
7602
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
15111
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
2223
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
2492
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 render it within my control it crashes and burns. I've even tried placing it within another control (a PlaceHolder) and tried to render the PlaceHolder to no avail. Any ideas on how to fix this problem? Here's my code:
1
4941
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 nodes 1 to 10, but when the user clicks , the tree will display nodes 11 to 20. Page 1 will is loaded when the page that contains the ascx (parent of the treeview) is loaded. This is all cool. The treeview displays correctly. When I click the ...
0
9930
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10720
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10403
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7113
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.