Return to Snippet

Revision: 6208
at May 7, 2008 15:44 by PUN1SH3R


Initial Code
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

Initial URL

                                

Initial Description
This code allows you to check the parent node in a TreeView control when the last child node is checked.

Initial Title
Check Parent Node When Last Child is Checked

Initial Tags

                                

Initial Language
VB.NET