Got It!
The key is the mouse_up event occurs After the node_check event.
Heres some code to illustrate how its done:
VB Code:
Dim let_me_check As Boolean Dim mouse_down As Boolean Dim C_NODE As Node Private Sub Form_Load() Dim nodX As Node ' Declare the object variable. Dim NodY As Node Dim I As Integer ' Declare a counter variable. For I = 1 To 4 Set nodX = TreeView1.Nodes.Add(, , , "Node " & CStr(I)) For J = 1 To 4 Set NodY = TreeView1.Nodes.Add(nodX, tvwChild, , "Node " & I & J) Next J Next I End Sub 'it doesn't seem needed, but as a looping safety precaution 'the mouse_down boolean signifies that, if a node_check occured 'while mouse_down is true, it occured from the user physically 'checking it. 'ie.. if you uncheck or check it programically, You won't start looping 'if you use it correctly Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) mouse_down = True End Sub Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) 'of course, mouse_up occurs after mouse_down, so we dont need to check the mouse_down bool 'but, still reset it to false mouse_down = False 'if a node was checked, then let_me_check indicates you need to inspect the node value 'against your conditions. Just for testing, 'Im checking the passed node value against the check controls check value. 'In this routine, it allows un-checking when Check1 = 1, 'but not checking when check1.Value = 1 If let_me_check = True Then 'place your inspection routine inside this if...endif If (Check1.Value = 1) And (C_NODE.Checked = True) Then C_NODE.Checked = False End If let_me_check = False End If End Sub Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node) 'if the check occured from a mouse_down event, then do a setup 'on the variables needed for your inspection routine. If mouse_down = True Then Set C_NODE = Node let_me_check = True End If End Sub
and I attached my development project.
-Hope this helps
-Lou
![]()




Reply With Quote