By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,668 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,668 IT Pros & Developers. It's quick & easy.

How to select root node in TreeView?

P: n/a
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.
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"someone" <a@a.com> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
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.

Nov 13 '05 #2

P: n/a
"someone" <a@a.com> wrote in news:Oo**************@tk2msftngp13.phx.gbl:
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

--
Solutions Design : http://www.sd.nl
My open source .NET Software : http://www.sd.nl/software
My .NET Blog : http://weblogs.asp.net/FBouma
-------------------------------------------------------------------------
Nov 13 '05 #3

P: n/a
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
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.