selecting TreeView Node

  • Thread starter Thread starter UmmagummA
  • Start date Start date
U

UmmagummA

Is it possible to select a TreeNode in a TreeView from code?

There isn't a property Focused nor a func Focus(). I tried with (all the
Nodes are collapsed in this moment):

TreeViewObject.SelectedNode = aSpecifiedTreeNode;

but it doesn't work. After this assignment SelectedNode remeins <undefined
value>.
 
Hi,

You can use the mouse down event to find out which node has been clicked by
the user.

private void treeView1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
TreeNode selectedNode = null;
selectedNode = treeView1.GetNodeAt(e.X,e.Y);
}

The selectedNode will contain the Node that was clicked by the user.
 
Back
Top