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
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.
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) 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With