473,471 Members | 4,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

treeview right click select opening contextMenuStrip

3 New Member
I have a treeview opening a contextMenuStrip on right click. However the right click would not select the node that it right clicks on. How should I make it so the right click will select the node, and open the contextMenuStrip on that node?

I tried this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  3. if (e.Button == MouseButtons.Right)
  4. {
  5. treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y);
  6. }
  7. }
  8.  
I found solutions online all points to using MouseDown or MouseUp as a solution. It selects the node when my right mouse button is still holding down. However on release of the button, the node that I selected before the right click becomes the selected node and contextMenuStrip opens on this selected node.


I tried setting a breakpoint in the if statement of MouseDown, however, it seems like it never even called the function! How weird...
Jun 23 '08 #1
1 9892
cloud255
427 Recognized Expert Contributor
Try this:

create the control, then select the NodeMouseClick event.

Expand|Select|Wrap|Line Numbers
  1. private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  2.         {
  3.             if (e.Button.Equals(MouseButtons.Right))
  4.             {
  5.                 treeView1.SelectedNode = treeView1.Nodes[e.Node.Index];
  6.                 contextMenuStrip1.Show(MousePosition);
  7.             }
  8.         }
this works fine for me.
Jun 24 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Phill | last post by:
Here's what I'm doing to make the right context mnue show up based on what node was cliked: private void tvwMenu_MouseUp(object sender, MouseEventArgs e) { //Select Node When Right Clicked &...
3
by: vijaynats | last post by:
I have a treeview with a ContextMenu attached. When i click on a node, AfterSelect fires but does not fire when right clicked (the context menu pops up). (Background: I have loaded a list of...
4
by: humble.apprentice | last post by:
Hi everybody, I've got a TreeView and when ever I right-click on it, the ContextMenuStrip should comes up. The problem is the following, if the user didn't left-click an then right click the...
1
by: Aleksey | last post by:
Hi, All! I have a problem with TreeView component. My TreeView consists of two nodes Node1 and Node2. On click of right mouse button TreeView has event. In this event I check wich node is...
5
by: A-PK | last post by:
Hi, I am using treeview as my menu. my menu is like the following + Users & Groups - Users -Groups + Departmenuts - Engineering
0
by: kvrdeveloper1 | last post by:
Hello all, I am populating my treeview with only 1 level of items. Upon opening my screen, I call the RefreshTreeview routine which populates the treeview just fine, and I am able to click on...
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
7
by: Joe Cool | last post by:
Let's say I have a Treeview control on a form. Each leaf node in the Treeview has a ContextMenuStrip, each with one ToolStripMenuItem, and all ToolStripMenuItems Click event is handled by a comment...
6
by: Eng Teng | last post by:
How do I write a code to activate a popup menu when I right click in a label control? Regards, Tee
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.