We help IT Professionals succeed at work.

How to select a node in the tree control programatically in vb.net

I have a populated tree control, and I want programatically to set focus (with highlight) to a specific node, that could be in the visible area or not (including moving to the top or bottom. How to do that programatically in vb.net
Thanks in advance
Comment
Watch Question

Commented:
Me.TreeView1.SelectedNode = Me.TreeView1.Nodes(1)

This will select the second root node

To select the first child node of a second root node use this:

Me.TreeView1.SelectedNode = Me.TreeView1.Nodes(1).Nodes(0)
icr

Commented:
Bear in mind that the treeview may not be focussed (depending on when you are selecting the node). If you want to subsiquently focus it you can use Me.TreeView1.Focus()
Commented:
Additionaly you can set a HideSelection property to false to be able to see selected node even if TreeView is not focused.

Author

Commented:
Thank you slow mo