nik
nik

Reputation: 895

TreeView: checkboxes only in child nodes

I need a treeview control:

  1. Root nodes don't have checkboxes, only images.
  2. All child nodes have a checkbox + image.

C#, .net 2.0, winforms (not wpf)

Upvotes: 3

Views: 14658

Answers (2)

Linojan
Linojan

Reputation: 168

You can disable checkbox. First Set TreeView DrawMode property as OwnerDrawAll. Then Under DrawNode method check child node collection and set checked property as false ie.

private void xmlStructureTree_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            if (e.Node.Nodes.Count != 0)
            {
                e.Node.Checked = false;
            }
            e.DrawDefault = true;
        } 

Upvotes: 0

vc 74
vc 74

Reputation: 38179

The WinForms tree view does not support mixed checkbox/non checkboxes nodes by default

You can enable CheckBoxes globally on the tree view and disable them on specific nodes using this method

Upvotes: 2

Related Questions