How to select root node in TreeView?

  • Thread starter Thread starter someone
  • Start date Start date
S

someone

Here is my code:
TreeNodeCollection nodes = tvwFolders.Nodes;
if (nodes.Count > 0)
{
// Select the root node
tvwFolders.SelectedNode = nodes[0];
}

I hope there is an easier way. I looked at TreeView.TopNode, but that is the
top "visible" node. I would think that getting the absolute top node should
be easy, isn't it? Is there a property or method I missed?

Thanks.
 
someone said:
Here is my code:
TreeNodeCollection nodes = tvwFolders.Nodes;
if (nodes.Count > 0)
{
// Select the root node
tvwFolders.SelectedNode = nodes[0];
}

I hope there is an easier way. I looked at TreeView.TopNode, but that is
the top "visible" node. I would think that getting the absolute top node
should be easy, isn't it? Is there a property or method I missed?

I always store important nodes in membervariables of the class (form)
which holds the treeview. Also object to node collections are an option if
you have to lookup nodes frequently. Saves a lot of time.

FB
 
TreeNodeCollection nodes = tvwFolders.Nodes;
if (nodes.Count > 0)
{
// Select the root node
tvwFolders.SelectedNode = nodes[0];

// give the focus to the treeview
tvwFolders.Focus();
}

HTH
 
Hi,

Did you ever find an answer to this. I would like to be able to select any node passing it an index, text or tag.

Thanks,
Kelvin
 
Back
Top