Skip to main content
All docs
V24.2

DxTreeList.EditCanceling Event

Fires before the TreeList cancels the edit operation and discards changes.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public EventCallback<TreeListEditCancelingEventArgs> EditCanceling { get; set; }

Parameters

Type Description
TreeListEditCancelingEventArgs

An object that contains data for this event.

Remarks

The EditCanceling event occurs in the following cases:

  • A user presses Esc in the pop-up edit form.
  • A user clicks the Cancel button in the edit form or command column.
  • In EditCell mode, a user presses Esc when an editor in the focused data cell is hidden.
  • In EditCell mode, a user performs a data shaping operation that hides the edited row from the view and row validation fails.
  • The CancelEditAsync method is called.

Handle this event to create a custom response to the edit cancel action. Use the IsNew event argument to identify whether a new or existing data item is being edited. DataItem, ParentDataItem, and EditModel properties return processed data item, its parent, and edit model. The TreeList property allows you to access the TreeList and its extensive API.

Set the Cancel property to true to prevent the cancel action. The following example prevents the cancel action for new rows:

@inject EmployeeTaskService EmployeeTaskService

<DxTreeList Data="TreeListData"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            EditMode="TreeListEditMode.EditForm"
            CustomizeEditModel="TreeList_CustomizeEditModel"
            EditModelSaving="TreeList_EditModelSaving"
            EditCanceling="TreeList_EditCanceling">
    <Columns>
        <DxTreeListCommandColumn DeleteButtonVisible="false" />
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
    <EditFormTemplate Context="EditFormContext">
        <DxFormLayout CssClass="w-100">
            <DxFormLayoutItem Caption="Task:" ColSpanMd="6">
                @EditFormContext.GetEditor("Name")
            </DxFormLayoutItem>
            <DxFormLayoutItem Caption="Employee Name:" ColSpanMd="6">
                @EditFormContext.GetEditor("EmployeeName")
            </DxFormLayoutItem>
            <DxFormLayoutItem Caption="Start Date:" ColSpanMd="6">
                @EditFormContext.GetEditor("StartDate")
            </DxFormLayoutItem>
            <DxFormLayoutItem Caption="Due Date:" ColSpanMd="6">
                @EditFormContext.GetEditor("DueDate")
            </DxFormLayoutItem>
        </DxFormLayout>
    </EditFormTemplate>
</DxTreeList>

@code {
    List<EmployeeTask> TreeListData { get; set; }

    protected override void OnInitialized() {
        TreeListData = EmployeeTaskService.GenerateData();
    }
    async Task TreeList_EditCanceling(TreeListEditCancelingEventArgs e) {
        if (e.IsNew)
            e.Cancel = true;
    }
    void TreeList_CustomizeEditModel(TreeListCustomizeEditModelEventArgs e) {
        if (e.IsNew) {
            var newTask = (EmployeeTask)e.EditModel;
            newTask.Id = TreeListData.Max(x => x.Id) + 1;
            if (e.ParentDataItem != null)
                newTask.ParentId = ((EmployeeTask)e.ParentDataItem).Id;
        }
    }
    async Task TreeList_EditModelSaving(TreeListEditModelSavingEventArgs e) {
        if (e.IsNew)
            TreeListData.Add((EmployeeTask)e.EditModel);
        else
            e.CopyChangesToDataItem();
    }
}

Refer to the following topic for more information: Editing and Validation in Blazor TreeList.

See Also