473,624 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

treeview right click select opening contextMenuStri p

3 New Member
I have a treeview opening a contextMenuStri p 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 contextMenuStri p 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 contextMenuStri p 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 9923
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
11586
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 & Set Context Menu To Use if( e.Button == MouseButtons.Right ) { TreeNode node = tvwMenu.GetNodeAt( new Point( e.X, e.Y ) ); if( node != null )
3
11615
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 disk file names onto the tree and have to open the file thru the contextmenu for editing. It opens the file whose treeview node was selected earlier using a left mouse click). Any solutions?
4
7168
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 node he or she desired, the ContextMenuStrip will show the options for the node that was left-clicked before. How can I make it work like explorer does that it doesn't need to be left-clicked and then right -clicked? I will appreciate if you can...
1
3086
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 selected. At the start Node1 is selected. But when I do right click on Node2 the selected node remain Node1. It changed only after left click. Q: How can I check on wich node was right click? Or how can I make TreeView to change selected node by node...
5
1547
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
3114
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 nodes in the treeview and populate the appropriate data accordingly. However, once I add a new record via this screen and call the same RefreshTreeview routine (which successfully populates the treeview with the appropriate items including the new...
8
12749
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 form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if every time that a user selects a node, the whole page has to reload. Is there a way to have a node...
7
7833
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 event handler. How do I determine which Treeview Node signalled the menu event in the common event handler?
6
2178
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
8238
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8336
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7164
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6111
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
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 we have to send another system
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.