Link to home
Start Free TrialLog in
Avatar of arajoe
arajoe

asked on

Looping through nodes in a tree

I have a VB6 program with a tree in a form. I already have the tree all populated. What I want to do know is build in the logic that if all of the children of a parent are checked then the parent itself will be checked, or true. If someone could please point me in the right direction with a sample of code, that would be great. Thanks, arajoe.
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arajoe
arajoe

ASKER

Thanks to everyone. I went with the answer I did because it allowed for a more recursive function. The code I ended up with is below. Thanks again, arajoe.


Private Sub Check_Parents(ByRef Node As MSComctlLib.Node, ByVal Node_Checked_Value As Boolean)

    Dim Child As MSComctlLib.Node
    Dim All_Checked As Boolean
   
    If Node.Children > 0 Then
        Set Child = Node.Child
        Do While Not Child Is Nothing
       
            Child.Checked = Node_Checked_Value
           
            UnAssign_SUP Child
           
            Check_Parents Child, Child.Checked
           
            Set Child = Child.Next
           
        Loop
    End If
   
    If Not Node.Parent Is Nothing Then
        All_Checked = True
        Set Child = Node.Parent.Child
        Do While Not Child Is Nothing
            If Not Child.Checked Then
                All_Checked = False
                Exit Do
            End If
            Set Child = Child.Next
        Loop
        Node.Parent.Checked = All_Checked
    End If
   
End Sub