Dealing with a MS Treeview 6.0 with the property set to use check boxes. Normally this process only check the node selected and ignores the parent child relationships
I have managed to get some code that automaticaly checks parent nodes when a node is checked and unchecks child nodes if the parent is unchecked...
I have however run into a problem...
The code checks or unchecks the node on the Mouse Down but it doesnt update the parent/child relationships until the Mouse Up
Not sure why it does this since the code inst specific to mouse down or mouse up events.
Regardless it is doing it and the problem is that if the mouse accidentally moves off of the check box before the Mouse Up then the update doesnt occur and the node gets "abandoned"
Anyone have anyideas on how to resolve this
Here is the code for the NodeCheck
Private Sub TreeViewLocation_NodeCheck(ByVal Node As Object)
On Error Resume Next ' In case there are no parents or parent.parents
Dim NodX As Node, NodY As Node, NodZ As Node, strNodeKey As String
If Node.Checked Then
Node.Parent.Checked = True
Node.Parent.Parent.Checked = True
Else
strNodeKey = Node.Key
For Each NodX In Me!TreeViewLocation.Nodes
Set NodY = NodX.Parent
Set NodZ = NodY.Parent
If Not NodY Is Nothing Then
If NodY.Key = strNodeKey Then NodX.Checked = False
End If
If Not NodZ Is Nothing Then
If NodZ.Key = strNodeKey Then NodX.Checked = False
End If
Next NodX
End If
End Sub
Just an FYI in my tree view there are three nodes.
I have managed to get some code that automaticaly checks parent nodes when a node is checked and unchecks child nodes if the parent is unchecked...
I have however run into a problem...
The code checks or unchecks the node on the Mouse Down but it doesnt update the parent/child relationships until the Mouse Up
Not sure why it does this since the code inst specific to mouse down or mouse up events.
Regardless it is doing it and the problem is that if the mouse accidentally moves off of the check box before the Mouse Up then the update doesnt occur and the node gets "abandoned"
Anyone have anyideas on how to resolve this
Here is the code for the NodeCheck
Private Sub TreeViewLocation_NodeCheck(ByVal Node As Object)
On Error Resume Next ' In case there are no parents or parent.parents
Dim NodX As Node, NodY As Node, NodZ As Node, strNodeKey As String
If Node.Checked Then
Node.Parent.Checked = True
Node.Parent.Parent.Checked = True
Else
strNodeKey = Node.Key
For Each NodX In Me!TreeViewLocation.Nodes
Set NodY = NodX.Parent
Set NodZ = NodY.Parent
If Not NodY Is Nothing Then
If NodY.Key = strNodeKey Then NodX.Checked = False
End If
If Not NodZ Is Nothing Then
If NodZ.Key = strNodeKey Then NodX.Checked = False
End If
Next NodX
End If
End Sub
Just an FYI in my tree view there are three nodes.