4
votes

Using the TreeView control in WinForms, is there a property that can be set to hide the collapse-node icons for each node?

Also, how do I permanently expand all nodes in the TreeView?

3
Hi @Blaxx just to make sure, is this a asp.net TreeView or winforms TreeView?Alex KeySmith
No worries, so just to make sure; so on a webpage (asp.net) or winforms (i.e. .net on the desktop) ?Alex KeySmith
ah, this is what you mean, winformsBlaxx
Hi @Blaxx I'm not sure what you mean by the "forbid expand-nodes"? And "I want the nodes to be visible all the time."? Do you mean that you want the top level nodes to be visible, but all the subnodes to be hidden and not viewable?Alex KeySmith

3 Answers

3
votes

You would need to handle the OnBeforeExpand event and set Cancel to true.

private void OnBeforeExpand(TreeViewCancelEventArgs e)
{
   e.Cancel = true;
}

Keep in mind that this would prevent any tree node from expanding.

If you want to hide the "+/-" symbols, you should set the ShowPlusMinus property to false.

2
votes

You could try handling the BeforeCollapse event and setting the e.Cancel = true, always.

1
votes

You can intercept the TreeView.BeforeCollapse event

private void YourBeforeCollapseEventHandler(object sender, TreeViewCancelEventArgs e)
{
    e.Cancel = true;
}