How to select root node in TreeView?

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.
 
F

Frans Bouma

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
 
K

Kalpesh Shah

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
 
G

Guest

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
 

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

Top