Determine Left or Right mouse click on a treeview Item

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hi,

I am looking for my program to be notified when a user right clicks on a
particular treenode.

I have placed my code in the "click" event, and I am indeed notified when a
user clicks on the node.

however what I would like to do is be able to tell which mouse button was
used (left or right)

can anybody tell me if this is possibe please and point me in the direction
of a solution to my problem.

Also i am having a little difficulty obtaining the name of the node in the
click event.

The specific code is

Private Sub TreeView1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TreeView1.Click
Dim objNode As New TreeNode
objNode = CType(sender, TreeNode) <---------This cast is aparently
invalid so not sure how to obtain the node name
MessageBox.Show("Button clicked")
MessageBox.Show(objNode.Text)
'Now decide which mouse button was clicked'
NOT sure how to do thos of if this is the correct event to obtain this
info........

End Sub

many thanks in advance.

cheers

martin.
 
* "Martin said:
I am looking for my program to be notified when a user right clicks on a
particular treenode.

I have placed my code in the "click" event, and I am indeed notified when a
user clicks on the node.

however what I would like to do is be able to tell which mouse button was
used (left or right)

\\\
Private Sub TreeView1_MouseUp( _
ByVal sender As Object, _
ByVal e As MouseEventArgs _
) Handles TreeView1.MouseUp
If e.Button = MouseButtons.Right Then
Dim n As TreeNode = Me.TreeView1.GetNodeAt(e.X, e.Y)
If Not n Is Nothing Then
Me.TreeView1.SelectedNode = n
Me.MenuItem1.Text = n.Text
Else
Me.MenuItem1.Text = "(no item selected)"
End If
Me.ContextMenu1.Show(Me.TreeView1, New Point(e.X, e.Y))
End If
End Sub
///
 
Hi Herfried,

Thank you for your answer, once again.

I will master these treeviews one day ... hopefully :)

cheers

martin.
 
Back
Top