Hi there.
The Following subroutine ensures that in no matter what index order of a Treeview, the children and grandchildren of a node becomes checked or non-checked accordingly to the parent node.
I hope you can use this :-)
Regards
Casper
---VB CODE---
Private Sub subNodeCheck(ByVal Node As MSComctlLib.Node)
Dim nodLast As Node
Dim nodNext As Node
If Node.Children > 0 Then
Set nodNext = Node.Child.FirstSibling
Set nodLast = Node.Child.LastSibling
If Node.Checked = False Then
Do Until nodNext = nodLast
nodNext.Checked = False
' has the childnode any children?
If nodNext.Children > 0 Then Call subNodeCheck(nodNext)
' moving on to the next node
Set nodNext = nodNext.Next
Loop
' Just for kicks - let's ensure the lastsibling is unchecked
nodLast.Checked = False
Else
Do Until nodNext = nodLast
nodNext.Checked = True
' Has the Childnode any children?
If nodNext.Children > 0 Then Call subNodeCheck(nodNext)
' moving on to the next node
Set nodNext = nodNext.Next
Loop
nodLast.Checked = True
End If
' Has the last sibling any children?
If nodLast.Children > 0 Then Call subNodeCheck(nodLast)
End If
End Sub
Private Sub treeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
Call subNodeCheck(Node)
End Sub
