473,787 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Right Click to Select on TreeView

This may be a simple question but how can I make the tree change the
selected node... on a right click .. in addition to the left click?

What I want is to filter my context menu based on the type of node selected
but the left click doesn't seem to change the selected node.

Thanks,

Nov 20 '05 #1
1 2462
* "Patrick" <py**@oneshield .com> scripsit:
This may be a simple question but how can I make the tree change the
selected node... on a right click .. in addition to the left click?


\\\
Private Sub TreeView1_Mouse Up( _
ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs _
) Handles TreeView1.Mouse Up
If e.Button = MouseButtons.Ri ght Then
Dim n As TreeNode = Me.TreeView1.Ge tNodeAt(e.X, e.Y)
If Not n Is Nothing Then
Me.TreeView1.Se lectedNode = n
Me.MenuItem1.Te xt = n.Text
Else
Me.MenuItem1.Te xt = "(no item selected)"
End If
Me.ContextMenu1 .Show(Me.TreeVi ew1, New Point(e.X, e.Y))
End If
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2949
by: Billy Jacobs | last post by:
I have a treeview control in my application. If I right- click a node, it highlights the node but does not set it to be selected. If you move off the control it highlights the previously selected node. In the Mouse_Down event if I check the treeview's selected node it is the previously selected node, not the one I right clicked. I need to get the node from the right-click because I have
2
2133
by: worzel | last post by:
Can't suss this out for the life of me, googling of no help either. Okay, new to win forms; I have a treeview with several root nodes, each having a single level of child nodes underneath. I also havea context (popup) menu which, what I want, is for it to pop up with certain options (menuItems) when a root treeNode is selected and different options when a child node is selected. It is all working well except for one problem - if I right...
2
10294
by: paradox | last post by:
How can I go about having a TreeNode selected when I right click? I tried using the Click event, but the event does not pass in the node that was clicked. Currently you have to left click a node in order to select it. I want to be able to write click and bring up a context menu with only certain options available depending on the node selected. I got the context menu to come up (which is very easy to do), however, you first have to left...
3
11630
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
7181
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
2128
by: Juan Romero | last post by:
Hey guys, I have a small problem here.... I have a treeview control. I want to display a popup menu when the user right clicks on a node. This is no problem, and I am able to make the popup come out. However, when I want to perform an operation based on the node selected, I find that the node actually gets selected after the popup goes away. In other words, if I right click a random item in the treeview and the user selects an...
2
7092
by: tmaster | last post by:
I can detect a right click on my treeview, but SelectedNode.Index points to the last node that was left-clicked. Is there a way for a right-click event of a treeview to update the SelectedNode.Index? Private Sub tvwTopics_Mouseup(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwTopics.MouseUp If e.Button = MouseButtons.Right Then MsgBox("Right click " &...
6
1923
by: Alan T | last post by:
Can I find out which node was right clicked on a treeview?
1
2740
by: karthee | last post by:
I am creating a custom treeview with multiple selection, if i select multiple nodes and right click, the selection is disappearing, i tried with somany things like on mouse click my code is like this if (e.Button != MouseButtons.Right) { if (ModifierKeys == Keys.None &&
1
9944
by: johnnypung | last post by:
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: private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Right) { treeView1.SelectedNode = treeView1.GetNodeAt(e.X,...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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...
0
10169
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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
7517
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
6749
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.