467,161 Members | 905 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

Treeview node right click

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.
Nov 20 '05 #1
  • viewed: 13998
Share:
2 Replies
"Juan Romero" <ju******@optonline.net> schrieb:
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
///

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2
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

"Juan Romero" <ju******@optonline.net> wrote in message
news:O9**************@tk2msftngp13.phx.gbl...
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.

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by vijaynats@yahoo.com | last post: by
1 post views Thread by Aleksey | last post: by
5 posts views Thread by A-PK | last post: by
3 posts views Thread by Shawn | last post: by
8 posts views Thread by Matt MacDonald | last post: by
18 posts views Thread by =?Utf-8?B?TGkgV2VuZw==?= | last post: by
reply views Thread by =?Utf-8?B?V2FubmFiZQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.