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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top