Back to Devexpress

ASPxTreeList.CommandColumnButtonInitialize Event

aspnet-devexpress-dot-web-dot-aspxtreelist-dot-aspxtreelist-39fb1df4.md

latest5.1 KB
Original Source

ASPxTreeList.CommandColumnButtonInitialize Event

Enables individual command buttons to be initialized.

Namespace : DevExpress.Web.ASPxTreeList

Assembly : DevExpress.Web.ASPxTreeList.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event TreeListCommandColumnButtonEventHandler CommandColumnButtonInitialize
vb
Public Event CommandColumnButtonInitialize As TreeListCommandColumnButtonEventHandler

Event Data

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

PropertyDescription
ButtonTypeGets the type of the command button currently being initialized.
CommandColumnGets a command column which owns the processed command button.
CustomButtonIndexGets the processed command button’s index.
EnabledGets or sets whether the processed command button is enabled.
NodeKeyGets the key of a node which contains the processed command button.
VisibleGets or sets whether the command button is visible.

The event data class exposes the following methods:

MethodDescription
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.

aspx
<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>
csharp
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;
}
vb
Protected Sub ASPxTreeList1_NodeDeleting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataDeletingEventArgs)
    Throw New Exception("Data modifications are not allowed in the online example.")
End Sub
Protected Sub ASPxTreeList1_CommandColumnButtonInitialize(ByVal sender As Object, ByVal e As TreeListCommandColumnButtonEventArgs)
    If e.ButtonType <> TreeListCommandColumnButtonType.Delete Then
        Return
    End If

    If ASPxTreeList1.FindNodeByKeyValue(e.NodeKey).ChildNodes.Count <> 0 Then
        e.Visible = DevExpress.Utils.DefaultBoolean.False
    End If
End Sub

See Also

Tree List

ASPxTreeList Class

ASPxTreeList Members

DevExpress.Web.ASPxTreeList Namespace