Skip to main content
All docs
V24.2

DxTreeList.EditStart Event

Fires before the TreeList starts editing a row.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public EventCallback<TreeListEditStartEventArgs> EditStart { get; set; }

Parameters

Type Description
TreeListEditStartEventArgs

An object that contains data for this event.

Remarks

The EditStart event occurs in the following cases:

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

You can set the Cancel event argument to true to prevent users from editing specific rows. The following code snippet prevents users from editing unselected rows:

@inject EmployeeTaskService EmployeeTaskService

<DxTreeList Data="TreeListData"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            EditModelSaving="TreeList_EditModelSaving"
            CustomizeEditModel="TreeList_CustomizeEditModel"
            AllowSelectRowByClick="true"
            SelectionMode="TreeListSelectionMode.Single"
            @bind-SelectedDataItem="@SelectedDataItem"
            EditStart="TreeList_EditStart">
    <Columns>
        <DxTreeListCommandColumn DeleteButtonVisible="false" />
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
</DxTreeList>

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

    protected override void OnInitialized() {
        TreeListData = EmployeeTaskService.GenerateData();
    }
    async Task TreeList_EditStart(TreeListEditStartEventArgs e) {
        if (!e.IsNew && !e.TreeList.IsDataItemSelected(e.DataItem))
            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