473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Treeview - different context menus for different nodes

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
1 1419
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rory | last post by:
I have an app that populates a treeview from an XML file. I want to create a few different context menus that pop up depending on which node is selected. I can get one context menu to appear when I...
4
by: alanrn | last post by:
I am using a TreeView to display the hierarchy of a strongly-typed collection (inherited from CollectionBase). The order of the nodes in the TreeView is strictly tied to the order in which they...
2
by: Trond Hoiberg | last post by:
Let say i have a bunch of files. Logfiles that is stored in subfolders. Folder1 --logfile1 --logfile2 --logfile3 Folder2 --logfile1 --logfile2 I want to display these files using data from...
5
by: Dotnet Gruven | last post by:
With this TreeView declaration: <asp:TreeView ID="Cloner" runat="server" SelectedNodeStyle-Font-Bold="true" SelectedNodeStyle-ForeColor="#003E21" OnTreeNodePopulate="PopulateNode"...
4
by: Martin | last post by:
I have a treeview control, which is docked on a panel. When I call the procedure to fill this treeview from the load event it works fine. It loads all nodes, and displays them nicely. However,...
4
by: John Dann | last post by:
I'm trying to implement a fairly simple Treeview procedure but running into problems. My Treeview has just two levels of nodes: top-level and one child level. I want a doube-click on the...
6
by: serge calderara | last post by:
Dear all, I was wondering is there is a way to customise the treView control in order to get any Control as a Node. What I try to do is having a Progress bar as a treeview node object. Is...
2
by: casManG | last post by:
I am working on a small project that uses the treeview control in .net 2003. I have a tree view that I am sending to a sub in order to iterate through the nodes. Public Sub test (ByVal...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.