Some applications, such as virus scanners, have a feature that when you check a parent node (such as one labeled "C:\") it will select all children of that node (such as each individual folder within "C:\").
The following code below is a recursive function that will check each node under a certain node and check or uncheck it.
VB Code:
Private Sub CheckChildren(Node As Node) Dim i As Integer, nodX As Node If Node.Children <> 0 Then 'If node has children Set nodX = Node.Child 'Catch first child For i = 1 To Node.Children 'Loop through each child nodX.Checked = Node.Checked 'Set as checked CheckChildren nodX 'Check to see if this node has children Set nodX = nodX.Next 'Catch next child Next 'Loop End If End Sub
It can be used as follows:
VB Code:
Private Sub Treeview1_NodeCheck(ByVal Node As MSComctlLib.Node) CheckChildren Node 'Call subroutine End Sub


Reply With Quote