Skip to main content
All docs
V24.2

DxTreeList.DataItemDeleting Event

Fires after a user confirms the delete operation in the delete confirmation dialog.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public EventCallback<TreeListDataItemDeletingEventArgs> DataItemDeleting { get; set; }

Parameters

Type Description
TreeListDataItemDeletingEventArgs

An object that contains data for this event.

Remarks

The DataItemDeleting event fires after a user confirms the delete operation in the delete confirmation dialog.

Blazor TreeList Delete Confirmation Dialog

Read Tutorial: Edit Model Read Tutorial: Edit Data Run Demo: Edit Data

Handle this event to check user access permissions, delete the data item from the underlying data source, and reload TreeList data. Use DataItem and ParentDataItem event arguments to obtain the processed data item and its parent.

The following example implements data editing in the TreeList component:

@inject EmployeeTaskService EmployeeTaskService

<DxTreeList Data="TreeListData"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            EditModelSaving="TreeList_EditModelSaving"
            DataItemDeleting="TreeList_DataItemDeleting"
            CustomizeEditModel="TreeList_CustomizeEditModel">
    <Columns>
        <DxTreeListCommandColumn />
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
</DxTreeList>

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

    protected override void OnInitialized() {
        TreeListData = EmployeeTaskService.GenerateData();
    }
    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();
    }
    async Task TreeList_DataItemDeleting(TreeListDataItemDeletingEventArgs e) {
        TreeListData.Remove((EmployeeTask)e.DataItem);
    }
}

After a DataItemDeleting event handler is processed, the TreeList removes the deleted data item from selection. If you do not delete this item from the data source, set the Cancel event argument to true to keep the item’s selection state.

Reload Data

TreeList data should be reloaded after you post updates to the data source. The TreeList component automatically reloads its data in response to the following actions:

  • After the EditModelSaving or DataItemDeleting event handler is executed.
  • After you change an instance of a field/property bound to the Data parameter.

In other cases, call the Reload() method to reload TreeList data.

If you call the Reload() method in the EditModelSaving or DataItemDeleting event handler to refresh data manually, set the Reload event argument to false to prevent unnecessary repeated reloads.

See Also