By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

Treeview - different context menus for different nodes

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


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

On 24 Aug 2004 10:08:16 -0700, ro****@hotmail.com (Rory) wrote:
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


Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.