I am working on a vb.net program. I have a treeview control on a form. What I want to do is to pop up a menu when user selects a node by RIGHT MOUSE. How can I do this? thanks.
Printable View
I am working on a vb.net program. I have a treeview control on a form. What I want to do is to pop up a menu when user selects a node by RIGHT MOUSE. How can I do this? thanks.
Maybe just attach a ContextMenu to your TreeControl?
thanks for your reply.
Actually my question is more detail, how to use the contextMenu control to create my menu? after that, how to popup it?
Paste a Context Menu to your form , and paste this code in the Mouse Up event of the treeview .
VB Code:
Private Sub TreeView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseUp If e.Button = MouseButtons.Right Then If Not Me.TreeView1.GetNodeAt(New Point(e.X, e.Y)) Is Nothing Then Me.TreeView1.SelectedNode = Me.TreeView1.GetNodeAt(New Point(e.X, e.Y)) Me.ContextMenu1.Show(Me.TreeView1, New Point(e.X, e.Y)) Else Me.TreeView1.SelectedNode = Nothing End If End If End Sub
thanks for the sample code. it helps a lot.
I guess first of all, I need create a popup menu. I drag a contextMenu control on my form, then I want to add "import" and "export" to it, how can do this?
You just need to fill in the context menuitems as it's main menuitems . Select the context menu control , when it's activated (in design time) ,you'll find it at the top of your form , then you can add items there .
thanks again. I just figure out how it works. my form is too big and the menu editor was out of my sight. silly me.