1

I have a System.Windows.Forms.TreeView control for which I would like to turn off the plus/minus sign for specific child TreeNode objects. I know I can do this at the entire TreeView level using the TreeView.ShowPlusMinus property, but I'm wondering if I can hide the signs only for selected TreeNode objects.

Abiel
  • 5,251
  • 9
  • 54
  • 74
  • Do you mean **without** removing the nodes? –  Jun 28 '11 at 20:02
  • @jp2code: Nodes are loaded dynamically by reading data from a web-service. Before each node is loaded into the tree I want to check if it should be a non-collapsible node, in which case I would want to disable the plus/minus sign (separately I would also put the node into expanded mode and disable the normal double-click expand/collapse behavior). After the node is added to the tree I do not need to adjust the plus/minus before again. – Abiel Jun 28 '11 at 20:16

4 Answers4

1

Alas, the Windows Forms TreeView class wraps the native tree view control, and that control only supports showing or hiding the plus/minus signs globally.

That's because, internally, that flag maps to the TVS_HASBUTTONS control style, which of course affects the whole control and not individual items.

To my knowledge, the only way to achieve what you want is to handle the DrawNode event and render everything yourself.

Community
  • 1
  • 1
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
0

Each TreeViewItem (TVITEM) has an cChildren member. If 0 the plusminus sign is hidden. if 1, the + sign is shown.

See http://msdn.microsoft.com/en-us/library/windows/desktop/bb773456%28v=vs.85%29.aspx

Dont forget the TVIF_CHILDREN flag.

I answer, because I searched the the same question and found no answer.

0

Based on your edit above, you should override your TreeView's BeforeCollapse event to cancel the collapse if it is a non-collapsible node:

private void treeView1_BeforeCollapse(object sender, TreeViewCancelEventArgs e) {
  MyParameter myP = e.Node.Tag as MyParameter;
  if (myP != null) {
    if (myP.Type == MyParameterType.NonCollapsible) {
      e.Cancel = true;
    }
  }
}
  • Sorry, I realized that my comment may have been slightly misleading. Instead of saying "disable" the plus/minus sign I should have said "hide". Basically I want to disable both the expand/collapse behavior and hide the plus/minus sign so that it is clear to the user that the node cannot be collapsed. The key thing I do not know how to do is to hide the plus/minus sign. – Abiel Jun 28 '11 at 20:42
  • I don't think that is possible with the built in control. If you want to go *off axis*, you will have to **roll your own**. –  Jun 28 '11 at 20:49
0

To remove plus/minus sign setLoadOnDemand to false;

Telerik.WinControls.UI.RadTreeNode Node = new Telerik.WinControls.UI.RadTreeNode();
Node.LoadedOnDemand = false;
m4n0
  • 29,823
  • 27
  • 76
  • 89
  • The question is about win forms (System.Windows.Forms.TreeView) and not telerik. Your post is not an answer to the question. – Guy Levy Oct 09 '21 at 13:59