Treeview tristate for parent node?

Lider

Member
Joined
Mar 12, 2021
Messages
8
Programming Experience
Beginner
automatically select or deselect the all child nodes whenever its parent Node is selected or deselected
vb.net:
Private Sub TreeView1_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterCheck
        Try
            e.Node.TreeView.BeginUpdate()
            If e.Node.Nodes.Count > 0 Then
                Dim parentNode = e.Node
                Dim nodes = e.Node.Nodes
                CheckedOrUnCheckedNodes(parentNode, nodes)
            End If
        Finally
            e.Node.TreeView.EndUpdate()
        End Try
    End Sub

    Private Sub CheckedOrUnCheckedNodes(ByVal parentNode As TreeNode, ByVal nodes As TreeNodeCollection)
        If nodes.Count > 0 Then
            For Each node As TreeNode In nodes
                node.Checked = parentNode.Checked
                CheckedOrUnCheckedNodes(parentNode, node.Nodes)
            Next node
        End If
    End Sub

The code works. Question: How to checkbox on parent node when selecting a child node - ThreeState?
 
Top Bottom