Treeview node right click

J

Juan Romero

Hey guys,

I am trying to detect a node right click event, but I can't seem to find a
way do this.

The only way I found to get to a point where I know the user clicked the
node is by checking the afterselect event of the treeview control. The Event
arguments variable has an action property which tells me whether the user
clicked the node, or expand it or whatever.

NOW, the problem is that once I check if the action was a mouseclick, HOW DO
I KNOW WHAT BUTTON WAS CLICKED?

Thanks in advance.
 
H

Herfried K. Wagner [MVP]

Juan Romero said:
I am trying to detect a node right click event

Quick and (very) Dirty:

\\\
Private Sub TreeView1_MouseUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.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
///
 
K

Kim Mitchell

I don't remember what I did exactly, but I do remember that there is
something in the treeview properties for setting a context menu after you
drag Context menu onto the form.

Kim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top