You might be confused because you mix up two different concepts: focusing and selection.
"Focusing" means getting keyboard focus, nothing else; showing of a visual clue of the focus is just one aspect of it. Normally the whole control is focused (I don't consider composite controls here, they can have children controls and only one of the "elementary" controls can be focused).
The
TreeView
control is the control which can be focused only as a whole control. Its nodes can be selected. Note that the nodes remain selected when the control is focused or not. You might argue: "What happens during in-place editing of the node text? It looks like the node is focused." No, node is never focused. Actually, when an in-place edition happens, whole tree view looses its focus, because a separate in-place text editor is created at the location of a tree node and temporarily grabs the focus.
You can get or set selected node using the property
System.Windows.Forms.TreeView.SelectedNode
, see
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx[
^].
See also the property affecting selection and presentation of selection:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.canselect.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.fullrowselect.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.hideselection.aspx[
^].
Most likely you will also need events raised on change in selection:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.onafterselect.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.onbeforeselect.aspx[
^].
Basically, that's all what involved.
—SA