ComponentOne TreeView for ASP.NET WebForms
Task-Based Help / Creating and Configuring Check Box Nodes / Preventing Child Nodes from Being Automatically Checked
In This Topic
    Preventing Child Nodes from Being Automatically Checked
    In This Topic

    When check boxes are utilized in a C1TreeView, clicking a parent node will automatically check all of its child nodes as well. To prevent this, you can set the C1TreeView's AutoCheckNodes property to False.

    In this tutorial, you will create a C1TreeView control with one parent node and two child nodes. You will change the nodes to check boxes and then set the AutoCheckNodes property to False so the child nodes' Checked property settings will be independent of its parent node's Checked property setting.

    Complete the following:

    1. Click the Source tab to switch to Source view.
    2. Add the following markup between the <cc1:C1TreeView> tags:
      Markup
      Copy Code
      <Nodes>
           <cc1:C1TreeViewNode runat="server" Text="Parent">
                <Nodes>
                     <cc1:C1TreeViewNode runat="server" Text="Child 1">
                     </cc1:C1TreeViewNode>
                     <cc1:C1TreeViewNode runat="server" Text="Child 2">
                     </cc1:C1TreeViewNode>
                </Nodes>
           </cc1:C1TreeViewNode>
      </Nodes>
      
    3. This markup creates a parent node with two child nodes.
    4. Enable the check boxes by adding ShowCheckBoxes="True" to the <cc1:C1TreeView> tag.
    5. Press F5 to run the project and complete the following to see how the check boxes behave by default:
      1. Expand the Parent node to reveal the TreeView hierarchy.
      2. Click the Parent check box and observe that the child nodes are automatically selected.

      3. Terminate the program.
    6. Click Design tab to enter Design view.
    7. In the Properties window, select C1TreeView1 from the drop-down list and then set the AutoCheckNodes property to False.
    8. Press F5 to run the project and complete the following to see how the check boxes behave when the nodes are no longer auto-checked:
      1. Expand the Parent node to reveal the TreeView hierarchy.
      2. Check the Parent check box and observe that the child tabs don't get checked automatically.

    If you check the Child 1 check box and leave the Child 2 check box, you'll notice that the Parent check box contains an "indeterminate" mark. If you want to prevent this from happening, set the C1TreeView control's AllowTriState property to False.
    See Also