R – Expand Windows Forms TreeView node without selecting it

treeviewwinforms

When I expand a TreeView node by clicking on the plus sign right to it, the node gets selected. How can I avoid this? I want to be able to expand nodes without changing the selected node (like in RegEdit.exe, for example), and only change selection when the node text is clicked .

(Forgive me for what seems to be a basic question – I did search around, but found nothing. Any pointers or links are welcome.)

Best Answer

I believe there is a BeforeSelect event you can tap into, which should allow you to cancel node selection if the selected node has children.

private void MyTreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
 If (nodeWithChildren) e.Cancel = True
}
Related Topic