aspnet-devexpress-dot-web-dot-aspxtreelist-dot-aspxtreelist-39fb1df4.md
Enables individual command buttons to be initialized.
Namespace : DevExpress.Web.ASPxTreeList
Assembly : DevExpress.Web.ASPxTreeList.v25.2.dll
NuGet Package : DevExpress.Web
public event TreeListCommandColumnButtonEventHandler CommandColumnButtonInitialize
Public Event CommandColumnButtonInitialize As TreeListCommandColumnButtonEventHandler
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. |
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.
This example illustrates how to hide the delete button for those nodes that have child nodes in the CommandColumnButtonInitialize event handler.
<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;
}
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