DotNet Academy of Rajesh Rolen

Solutions by Rajesh Rolen

Check/ Uncheck all child nodes of a node in TreeView

when we need to Check/ Uncheck all chield nodes of anynode in TreeView we need to create a recursive function which will do check all to all child nodes of the current node and voice-versa.

Private Sub tvrights_AfterCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvrights.AfterCheck
RemoveHandler tvrights.AfterCheck, AddressOf tvrights_AfterCheck
CheckChildNode(e.Node)
CheckParentNode(e.Node)
AddHandler tvrights.AfterCheck, AddressOf tvrights_AfterCheck
End Sub



Private Sub CheckChildNode(ByVal currNode As TreeNode)
'set the children check status to the same as the current node
Dim checkStatus As Boolean = currNode.Checked
For Each node As TreeNode In currNode.Nodes
node.Checked = checkStatus
CheckChildNode(node)
Next
End Sub

Private Sub CheckParentNode(ByVal currNode As TreeNode)
Dim parentNode As TreeNode = currNode.Parent
If parentNode Is Nothing Then Exit Sub
parentNode.Checked = True
For Each node As TreeNode In parentNode.Nodes
If Not node.Checked Then
parentNode.Checked = False
Exit For
End If
Next
CheckParentNode(parentNode)
End Sub

0 comments:

Post a Comment

About this blog

Blog Archive

My Blog List

Advertise On This Site

Site Info

Advertise on this Site

To advertise on this site please mail on RajeshRolen@gmail.com

Information Source

About

Pages

Dot Net Academy

Advertis in This Area of Site

Powered by Blogger.

Followers

Blog Archive

Search This Blog