We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Checked Nodes in Treeview

If I use the folowing code to walk through the checked nodes in a treeview will I ever get a child node BEFORE I get the parent node?

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

For Each tv As TreeViewNode In TreeView1.SelectedNodes

Text1.Text += tv.Text

Next tv

End Sub

1 Reply

VS Venkatesh S Syncfusion Team December 30, 2009 12:36 PM UTC

Hi Ron,

Thank you for your interest in Syncfusion products.

The child nodes can be retrieved before their parent node.

Following code snippet can be used to acheive your requirement

[C#]

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim allCheckedNodes As New List(Of TreeViewNode)()
childparent(TreeView1.Items, allCheckedNodes)
For Each tv As TreeViewNode In allCheckedNodes
Text1.Text += tv.Text
Next tv
End Sub

Protected Sub childparent(ByVal listItems As IList, ByVal list As List(Of TreeViewNode))
For Each tv As TreeViewNode In listItems
If tv.HasSubNodes Then
childparent(tv.Items, list)
End If
If tv.Checked AndAlso tv.ShowCheckBox Then
list.Add(tv)
End If
Next tv
End Sub


Please let us know if it helps you.

Regards
Venkatesh

Loader.
Live Chat Icon For mobile
Up arrow icon