-
Hello all! Just looking for simple code that will let me discern whether the user used the left or right mouse button (or middle for that matter) in a WHATEVERNODE_NodeClick() event. You would think Microsoft would just add a button reference like there is in the mousedown event, but WHY MAKE THINGS EASY! :)
Thanks to whoever answers.
-
Use MouseDown event
Node click doesn't care what button you clicked with. What you can do is to use a MouseDown event to check if the user clicked with the right mouse button.
Code:
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim nodCurrent As Node
If Button = vbRightButton Then
Set nodCurrent = TreeView1.HitTest(x, y)
If Not nodCurrent Is Nothing Then
nodCurrent.Selected = True
MsgBox "You right clicked on " & nodCurrent.Text
End If
End If
End Sub
-
I remember this pattern. You can use this one, it fires only if you click on a node.
Code:
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
TreeView1.Tag = Button
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As ComctlLib.Node)
Select Case TreeView1.Tag
Case 1
'Left button code here
Case 2
'Right button code here
End Select
End Sub