How to make a treeview uncollapsable?

2019-05-07 10:24发布

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条回答
可以哭但决不认输i
2楼-- · 2019-05-07 10:48

You can intercept the TreeView.BeforeCollapse event

private void YourBeforeCollapseEventHandler(object sender, TreeViewCancelEventArgs e)
{
    e.Cancel = true;
}
查看更多
叼着烟拽天下
3楼-- · 2019-05-07 10:54

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

查看更多
Ridiculous、
4楼-- · 2019-05-07 10:55

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.

查看更多
登录 后发表回答