Tuesday, February 17, 2009

How to get the selected node in tree view from MouseDown event using C#

C# - MouseDown event in Tree View Control

Here is a way to get the selected tree view node using C#. The snippet uses the X and Y co-ordinates to get the node

private void treeView1_MouseDown(object sender, MouseEventArgs e)

{

Point p1 = new Point(e.X, e.Y);

TreeNode N1 = treeView1.GetNodeAt(p1) ;

MessageBox.Show(N1.Text);

}

2 comments:

real Drouin said...

Who ever posted this solution never tried it in a NET application because it doesn't work

real Drouin said...

Same problem
This solution works only on WPC. It doesn't work on a .NET application

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005