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
Watch Question

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)

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()
Additionaly you can set a HideSelection property to false to be able to see selected node even if TreeView is not focused.


Thank you slow mo