/ Published in: VB.NET
This code allows you to check the parent node in a TreeView control when the last child node is checked.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Private Sub TreeView1_AfterCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck Dim blnUncheck As Boolean = False 'Check to see if a parent node exists. If Not e.Node.Parent Is Nothing Then 'Loop through the child nodes. For Each child As TreeNode In e.Node.Parent.Nodes 'Check to see if the current node is unchecked. If child.Checked = False Then 'Set the variable. blnUncheck = True End If Next 'Check the variable. If blnUncheck = False Then 'Check the parent node. e.Node.Parent.Checked = True Else 'Uncheck the parent node. e.Node.Parent.Checked = False End If End If End Sub