Wednesday, September 30, 2009

Visit all Nodes of TreeView

when we need to traverse all nodes of a treeview then we will have to create a recursive function.
In below example we are showing how to visit all nodes of treeview.
eg:-

Private Sub TraverseTreeView(ByVal tview As TreeView)
Dim temp As New TreeNode
For k As Integer = 0 To tview.Nodes.Count - 1
temp = tview.Nodes(k)
messagebox.show(temp) 'this will show node text
For i As Integer = 0 To temp.Nodes.Count - 1
visitChildNodes(temp.Nodes(i))
Next
Next
End Sub

Private Sub visitChildNodes(ByVal node As TreeNode)

messagebox.show(node) 'this will show node text
For j As Integer = 0 To node.Nodes.Count - 1
visitChildNodes(node.Nodes(j))
Next
End Sub

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates