Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Treeview highlight a node @ runtime

I am trying to figure out how to highlight a node on a treeview at runtime, I know the node index but cannot see how I can select it in Code. Also how can I collapse any other open node's and expand the selected one in code

thanks

like image 280
colin Avatar asked Feb 10 '12 16:02

colin


People also ask

How to highlight a node in TreeView c#?

But then I found the solution in another thread: Simply set the TabIndex of the TreeView to 0. In that case you don't need to set the focus. Just choose the node that should be selected by using SelectedNode and set the TabIndex . That's it.

How do I know if TreeView node is selected?

Solution 1 Use TreeView. SelectedNode[^] property, which get or set selected node for currently selected Treeview. If no TreeNode is currently selected, the SelectedNode property is a null reference (Nothing in Visual Basic).


1 Answers

1) Collapse the Treeview using the the FullCollapse method

TreeView1.FullCollapse;

2) To Select (highlight) a Node assign the Selected property

TreeView1.Selected:=TreeView1.Items[NodeIndex];

3) Expand the selected Node using the Expand method

TreeView1.Items[NodeIndex].Expand(True);
like image 113
RRUZ Avatar answered Oct 19 '22 12:10

RRUZ