Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
After I populate and expand all the nodes in the TreeView the focus is at the bottom of the Treeview. But how do I set the focus on the top root node of the Treeview after expanding all the nodes? Please Help.
Thanks in advance.
Posted
Updated 2-Jun-11 5:03am
v3
Comments
Sergey Alexandrovich Kryukov 1-Jun-11 17:44pm    
Tag, please. WPF, Forms, ASP.NET?
--SA
Monjurul Habib 1-Jun-11 18:22pm    
really important.
Sergey Alexandrovich Kryukov 2-Jun-11 1:44am    
I added a tag for you in your comment. Always do it yourself. You're interested the most, so the right expert would open your page.
--SA

1 solution

"Focus" is a wrong term. Nodes do not have focus (a control has). A node can only be selected or not. So, look at the methods related to selection. For example, use System.Windows.Forms.TreeView.SelectedNode read/write property.

This is for Forms. Do this simple exercise by yourself for other UI libraries:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.treeview.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.aspx[^].

Which one of those TreeView controls do you need?

Why didn't you tag the UI library you want to use? Always do it! We cannot read your mind.
If you did, you would get exact answer.

—SA
 
Share this answer
 
Comments
Monjurul Habib 1-Jun-11 18:22pm    
excellent links.my 5.
Sergey Alexandrovich Kryukov 1-Jun-11 18:23pm    
Thank you, Monjurul, but... nothing special, only a result of not tagging a question properly.
--SA
Member 7874093 2-Jun-11 0:50am    
Thanks for correcting me. Sorry I'm new to this forum. I am looking for the Windows forms Treeview.
Sergey Alexandrovich Kryukov 2-Jun-11 1:43am    
You still did not tag it. OK, for this UI library I already answered -- use TreeView.SelectedNode.
--SA
Sergey Alexandrovich Kryukov 2-Jun-11 1:45am    
If you got the answer, please accept it formally (green button).
Thank you.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900