Treeview node right click

  • Thread starter Thread starter Juan Romero
  • Start date Start date
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.
 
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
///
 
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
 
Back
Top