Skip to main content

ASPxTreeList.CommandColumnButtonInitialize Event

Enables individual command buttons to be initialized.

Namespace: DevExpress.Web.ASPxTreeList

Assembly: DevExpress.Web.ASPxTreeList.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public event TreeListCommandColumnButtonEventHandler CommandColumnButtonInitialize

Event Data

The CommandColumnButtonInitialize event's data class is TreeListCommandColumnButtonEventArgs. The following properties provide information specific to this event:

Property Description
ButtonType Gets the type of the command button currently being initialized.
CommandColumn Gets a command column which owns the processed command button.
CustomButtonIndex Gets the processed command button’s index.
Enabled Gets or sets whether the processed command button is enabled.
NodeKey Gets the key of a node which contains the processed command button.
Visible Gets or sets whether the command button is visible.

The event data class exposes the following methods:

Method Description
GetValue(String) Returns the value of the specified cell within the processed node.

Remarks

The CommandColumnButtonInitialize event is raised for each command button (edit, new, delete, etc.), and allows their settings to be initialized. For instance, you can hide or disable individual command buttons.

Example

This example illustrates how to hide the delete button for those nodes that have child nodes in the CommandColumnButtonInitialize event handler.

Tree List with hidden Delete Buttons

<dx:ASPxTreeList ID="ASPxTreeList1" runat="server" AutoGenerateColumns="False" 
                 DataSourceID="AccessDataSource1" KeyFieldName="EmployeeID" 
                 ParentFieldName="ReportsTo" EnableCallbacks="true" 
                 OnCommandColumnButtonInitialize="ASPxTreeList1_CommandColumnButtonInitialize" 
                 OnNodeDeleting="ASPxTreeList1_NodeDeleting">
    <Columns>
        <dx:TreeListTextColumn FieldName="LastName" />
        <dx:TreeListTextColumn FieldName="FirstName" />
        <dx:TreeListTextColumn FieldName="Title" />
        <dx:TreeListCommandColumn >
            <DeleteButton Visible="True" />
        </dx:TreeListCommandColumn>
    </Columns>
</dx:ASPxTreeList>
protected void ASPxTreeList1_NodeDeleting (object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) {
    throw new Exception("Data modifications are not allowed in the online example.");
}
protected void ASPxTreeList1_CommandColumnButtonInitialize (object sender, TreeListCommandColumnButtonEventArgs e) {
    if (e.ButtonType != TreeListCommandColumnButtonType.Delete)
        return;
    if (ASPxTreeList1.FindNodeByKeyValue(e.NodeKey).ChildNodes.Count != 0)
        e.Visible = DevExpress.Utils.DefaultBoolean.False;
}
See Also