473,385 Members | 1,337 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,385 software developers and data experts.

Getting the node the user right clicked on

Hi

In a treeview How do I get the node that the user right clicked on. I need
to modify the contecxt menu based on the node


Nov 17 '05 #1
4 3093
Hylton,

In .NET 2.0, you can call the HitTest method on the TreeView to get a
TreeViewHitTestInfo class instance which will have the node that the point
passed to the HitTest method points to (if there is one).

If not in .NET 2.0, you will have to call SendMessage through the
P/Invoke layer, passing the TV_HITTESTINFO message to get the location of
the the node at the specified coordinates.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Hylton" <Hy****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
Hi

In a treeview How do I get the node that the user right clicked on. I need
to modify the contecxt menu based on the node

Nov 17 '05 #2
Found another solution too.

private void treeView1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(MouseButtons.Right)
{
TreeNode node = treeView1.GetNodeAt(e.X, e.Y);
....
}
}

"Nicholas Paldino [.NET/C# MVP]" wrote:
Hylton,

In .NET 2.0, you can call the HitTest method on the TreeView to get a
TreeViewHitTestInfo class instance which will have the node that the point
passed to the HitTest method points to (if there is one).

If not in .NET 2.0, you will have to call SendMessage through the
P/Invoke layer, passing the TV_HITTESTINFO message to get the location of
the the node at the specified coordinates.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Hylton" <Hy****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
Hi

In a treeview How do I get the node that the user right clicked on. I need
to modify the contecxt menu based on the node


Nov 17 '05 #3
declare a global variable holding the last selected node.

private TreeNode currentNode;

handle the AfterSelect event of the treeview.

private void treeView1_AfterSelect(object sender,
System.Windows.Forms.TreeViewEventArgs e)

{

currentNode = e.Node;

}

handle the doubleclick and keydown events to capture the enter key.

private void treeView1_DoubleClick(object sender, System.EventArgs e)

{

MessageBox.Show(currentNode.Text);

}

private void treeView1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)

{

if(e.KeyCode == Keys.Enter)

{

MessageBox.Show(currentNode.Text);

}

}

note that doubleclick behaviour will be not desired if the mouse is not
clicked a node.
Nov 17 '05 #4
sorry i didnt see you wanted to capture right click..
Nov 17 '05 #5

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

Similar topics

0
by: hzgt9b | last post by:
Using visual studio .NET 2003, VB: I'm experiencing an issue with a TreeView object when it gets focus - the first root node in the tree always gets selected when the control gets focus - even if...
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 &...
0
by: adbarnet | last post by:
Hi, A second question... In my treeview control, I would like to offer the user the ability to right click on a tree-node, and depending on the type of node clicked provide them either a list...
6
by: Tim | last post by:
Hi I have a form with a treeview on it. When I select a particular node it adds/shows a tab on the form. The treeview node remains selected as it should. The user can close the tab or remove the...
2
by: Juan Romero | last post by:
Hey guys, I am trying to detect a node right click event, but I can't seem to find a way do this. The only way I found to get to a point where I know the user clicked the node is by checking...
5
by: B-Dog | last post by:
I want to be able to detect if a user has selected a parent or child node in a treeview and depending on which is clicked act accordingly based on the tag. I can get the values but don't know if...
6
by: Alan T | last post by:
Can I find out which node was right clicked on a treeview?
6
by: Proogeren | last post by:
I was wondering if there is a way to detect if the user clicks on a node in a treeview. I know of the onnodeclickchange event but this will not fire if you click on the same node twice (only fire the...
2
by: govolsbaby | last post by:
Hi All I've got a treeview with checkboxes. I want the user to be able to toggle the checkbox by click on the checkbox OR by clicking on the node text. So I've added an afterselect event...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.