Wednesday, September 30, 2009

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

Share This!


3 comments:

Anonymous said...

Simply want to say your article is as astounding.
The clarity in your publish is simply cool and i can assume you're an expert on this subject.
Fine together with your permission allow me to snatch your RSS feed to stay updated with
impending post. Thank you one million and please carry on the rewarding work.

Anonymous said...

Heya! I just wanted to ask if you ever have any issues with
hackers? My last blog (wordpress) was hacked and I ended up losing many months
of hard work due to no back up. Do you have any solutions to stop hackers?

Anonymous said...

Problema: aplicativos não podem ѕer baixados.

Powered By Blogger · Designed By Seo Blogger Templates