Back to Devexpress

ASPxTreeView.AllowCheckNodes Property

aspnet-devexpress-dot-web-dot-aspxtreeview-28f7564c.md

latest5.8 KB
Original Source

ASPxTreeView.AllowCheckNodes Property

Gets or sets a value that specifies whether the nodes checking feature is available.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(false)]
public bool AllowCheckNodes { get; set; }
vb
<DefaultValue(False)>
Public Property AllowCheckNodes As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

true if check boxes are available; otherwise, false.

|

Remarks

The ASPxTreeView allows end-users to check nodes using node check boxes. The AllowCheckNodes property controls the availability of check boxes for all nodes. For individual nodes, the visibility of their check boxes can be specified using the TreeViewNode.AllowCheck property on the node level. A particular node’s check box is enabled if both the control’s AllowCheckNodes and the node’s TreeViewNode.AllowCheck properties are set to true.

Note, that the AllowCheckNodes property doesn’t change a node’s checked status. It only hides/shows check boxes. The checked state of an individual node can be specified using the node’s TreeViewNode.Checked property.

For more information see the Check Box Support topic.

Example

This example demonstrates how you can use the AllowCheckNodes and AllowCheck properties to manage the visibility of check boxes.

aspx
<dx:ASPxRadioButtonList ID="ASPxRadioButtonList1" runat="server" 
    AutoPostBack="True" ClientIDMode="AutoID" 
    onselectedindexchanged="ASPxRadioButtonList1_SelectedIndexChanged" 
    SelectedIndex="0">
    <Items>
        <dx:ListEditItem Text="Hide all check boxes" Value="HideAll" />
        <dx:ListEditItem Text="Show check boxes for leaf nodes only" Value="ShowLeaves" />
        <dx:ListEditItem Text="Show all check boxes" Value="Show" />
    </Items>
</dx:ASPxRadioButtonList>

<dx:ASPxTreeView ID="ASPxTreeView1" runat="server" ClientIDMode="AutoID">
    <Nodes>
        <dx:TreeViewNode>
            <Nodes>
                <dx:TreeViewNode>
                    <Nodes>
                        <dx:TreeViewNode />
                        <dx:TreeViewNode />
                    </Nodes>
                </dx:TreeViewNode>
                <dx:TreeViewNode />
            </Nodes>
        </dx:TreeViewNode>
        <dx:TreeViewNode>
            <Nodes>
                <dx:TreeViewNode />
                <dx:TreeViewNode />
                <dx:TreeViewNode />
                <dx:TreeViewNode />
            </Nodes>
        </dx:TreeViewNode>
    </Nodes>
</dx:ASPxTreeView>

<dx:ASPxButton ID="ASPxButton1" runat="server" OnClick="ASPxButton1_Click" Text="Disable checked nodes" />
<dx:ASPxButton ID="ASPxButton2" runat="server" OnClick="ASPxButton2_Click" Text="Enable checked nodes" />
csharp
protected void Page_Load(object sender, EventArgs e) {
    if (!IsPostBack) {
        ASPxTreeView1.AllowCheckNodes = !(ASPxRadioButtonList1.SelectedIndex == 0);
        ASPxTreeView1.ExpandAll();
    }
}

protected void ASPxRadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) {
    ASPxRadioButtonList rblOptions = sender as ASPxRadioButtonList;
    switch (rblOptions.SelectedIndex) {
        case 0:
            ASPxTreeView1.AllowCheckNodes = false;
            break;
        case 1:
            ASPxTreeView1.AllowCheckNodes = true;
            PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, delegate(TreeViewNode node) { node.AllowCheck = node.Nodes.Count == 0; });
            break;
        case 2:
            ASPxTreeView1.AllowCheckNodes = true;
            PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, delegate(TreeViewNode node) { node.AllowCheck = true; });
            break;
    }
}

protected void PerformActionOnNodesRecursive(TreeViewNodeCollection nodes, Action<TreeViewNode> action) {
    foreach (TreeViewNode node in nodes) {
        action(node);
        if (node.Nodes.Count > 0)
            PerformActionOnNodesRecursive(node.Nodes, action);
    }
}
protected void ASPxButton1_Click(object sender, EventArgs e) {
    PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, delegate(TreeViewNode node) { node.Enabled = !node.Checked;});
}
protected void ASPxButton2_Click(object sender, EventArgs e) {
    PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, delegate(TreeViewNode node) { node.Enabled = true; });
}

See Also

Check Box Support

Member Table: Check Box Support

AllowCheck

Checked

Tree View

ASPxTreeView Class

ASPxTreeView Members

DevExpress.Web Namespace