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:
  1. Private Sub CheckChildren(Node As Node)
  2. Dim i As Integer, nodX As Node
  3.  
  4.   If Node.Children <> 0 Then 'If node has children
  5.     Set nodX = Node.Child 'Catch first child
  6.     For i = 1 To Node.Children 'Loop through each child
  7.       nodX.Checked = Node.Checked 'Set as checked
  8.      
  9.       CheckChildren nodX 'Check to see if this node has children
  10.      
  11.       Set nodX = nodX.Next 'Catch next child
  12.     Next 'Loop
  13.   End If
  14. End Sub

It can be used as follows:

VB Code:
  1. Private Sub Treeview1_NodeCheck(ByVal Node As MSComctlLib.Node)
  2.   CheckChildren Node 'Call subroutine
  3. End Sub