Treeview - different context menus for different nodes

R

Rory

Hi - I've seen quite a few posts that almost match this but haven't
found a solution that works.

I have an explorer-like application with a treeview in the lefthand
pane. When I right-click on a node, a context menu appears. How can I
get different context menus to appear depending on which node is
chosen. Here's my existing code:

Private Sub treeView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown

If e.Button = MouseButtons.Right Then
TreeView1.SelectedNode = TreeView1.GetNodeAt(e.X, e.Y)
Dim ClickPoint As Point = New Point(e.X, e.Y)
Dim ClickNode As TreeNode =
TreeView1.GetNodeAt(ClickPoint)
If ClickNode Is Nothing Then

Return

End If

' Show context menu

ContextMenu1.MenuItems.Clear()

ContextMenu1.MenuItems.Add("Add " &
TreeView1.SelectedNode.Text, New EventHandler(AddressOf
menuItemAdd_Click))

ContextMenu1.MenuItems.Add("Delete " &
TreeView1.SelectedNode.Text, New EventHandler(AddressOf
menuItemDelete_Click))

ContextMenu1.Show(TreeView1, clickpoint)
End If
 
J

Jason L James

Can you use the node.tag property to somehow
identify the type of node clicked and then create the
contect menu based on that.
 

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