Here it is a code to checked all children nodes
Function CheckChildren(ByVal Node As Object, _
Optional isChecked As Boolean = True) As Node
'---------------------------------------------------------------------------------------
' Procedure : CheckChildren
' DateTime : 09/06/2006 10:16
' Author : Edward Pivnik
' Purpose : Check/Uncheked recursively all children nodes to the Node
'---------------------------------------------------------------------------------------
On Error GoTo HandleError
Dim nNode As Node
If Node.Children > 0 Then ' There are children.
' Set first child's node
Set nNode = Node.Child
If Node.Children = 1 Then ' Only one child node
nNode.Checked = isChecked
CheckChildren nNode, isChecked
Else
' While nNode is not the index of the child node's
' last sibling, get next sibling's node.
While nNode.Index <> Node.Child.LastSibling.Index
nNode.Checked = isChecked
' call itselft to iterate through children nodes
CheckChildren nNode, isChecked
' Reset to next sibling's node.
Set nNode = nNode.Next
nNode.Checked = isChecked
' call itselft to iterate through children nodes
CheckChildren nNode, isChecked
Wend
End If
End If
ExitHere:
Exit Function
HandleError:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbCritical, "[Module].[Common ActiveX Control Operational].[CheckChildren]"
End Select
GoTo ExitHere
End Function
and here is a code to check all parents nodes. This is required if you
checked all children nodes on so parent node must be shown checked too
Function CheckParents(ByVal Node As Object) As Node
'---------------------------------------------------------------------------------------
' Procedure : CheckParents
' DateTime : 09/06/2006 10:49
' Author : Edward Pivnik
' Purpose : Check/Uncheked recursively all parents nodes to the Node
'---------------------------------------------------------------------------------------
'
On Error GoTo HandleError
Dim nNode As Node, n As Integer
Set nNode = Node.Parent
If Not nNode Is Nothing Then ' There is a parent node.
' Set first sibling's node
Set nNode = Node.FirstSibling
If nNode.Checked Then n = n + 1
' While nNode is not the index of the
' last sibling, get next sibling's node.
While nNode.Index <> Node.LastSibling.Index
' Reset to next sibling's node.
Set nNode = nNode.Next
If nNode.Checked Then n = n + 1
Wend
If n = Node.Parent.Children Then
Node.Parent.Checked = True
Else
Node.Parent.Checked = False
End If
' call itself to iterate through parent nodes
CheckParents Node.Parent
End If
ExitHere:
Exit Function
HandleError:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbCritical, "[Module].[Common ActiveX Control Operational].[CheckParents]"
End Select
GoTo ExitHere
End Function
Hi,
I have this code in below by cehrenre. It works well, but I have a question.
[quoted text clipped - 31 lines]