Skip to main content
All docs
V24.2

DxTreeList.StartEditRowAsync(Int32, String) Method

Starts editing the row with the specified visible index.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public Task StartEditRowAsync(
    int visibleIndex,
    string fieldName = null
)

Parameters

Name Type Description
visibleIndex Int32

A row visible index.

Optional Parameters

Name Type Default Description
fieldName String null

A field name that defines the column cell where to display an editor. If this parameter is omitted or the EditMode differs from EditCell, the method displays an editor in the first data column whose DataRowEditorVisible equals true.

Returns

Type Description
Task

A task that is completed when the row is in edit mode.

Remarks

The TreeList’s EditMode property specifies how users edit TreeList data. The StartEditRowAsync method behaves as follows depending on the active edit mode:

EditRow (Default)
Displays the edit row for the row with the specified visible index and focuses the first editor in the edit row.
EditForm
Displays the inline edit form for the row with the specified visible index and focuses the first editor in this form.
PopupEditForm
Invokes the pop-up edit form for the row with the specified visible index and focuses the first editor in this form.
EditCell

Displays and focuses an in-place editor in the cell associated with the specified field in the target row. The method ignores the fieldName parameter in the following cases:

  • No column is bound to the specified field.
  • The DataRowEditorVisible property of the column bound to the specified field is disabled.

When the fieldName parameter is omitted or ignored, the method displays an editor in the first data column whose DataRowEditorVisible is true.

Declare a DxTreeListCommandColumn object in the Columns template to display predefined New, Edit, and Delete command buttons in the TreeList component. Alternatively, you can create custom command elements inside or outside the TreeList. Handle a custom element’s click event and call the StartEditRowAsync method to start editing the row with the specified visible index.

The following code snippet displays icons instead of default command buttons:

@inject EmployeeTaskService EmployeeTaskService

<DxTreeList @ref="MyTreeList"
            Data="TreeListData"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            EditMode="TreeListEditMode.EditForm"
            EditModelSaving="TreeList_EditModelSaving"
            DataItemDeleting="TreeList_DataItemDeleting"
            CustomizeEditModel="TreeList_CustomizeEditModel">
    <Columns>
        <DxTreeListCommandColumn Width="90px">
            <HeaderTemplate>
                <a class="oi oi-plus" @onclick="@(() => MyTreeList.StartEditNewRowAsync())" style="text-decoration: none;" href="javascript:void(0);"></a>
            </HeaderTemplate>
            <CellDisplayTemplate>
                <a class="oi oi-pencil" @onclick="@(() => MyTreeList.StartEditRowAsync(context.VisibleIndex))" style="text-decoration: none;" href="javascript:void(0);"></a>
                <a class="oi oi-plus" @onclick="@(() => MyTreeList.StartEditNewRowAsync(context.VisibleIndex))" style="text-decoration: none;" href="javascript:void(0);"></a>
                <a class="oi oi-x" @onclick="@(() => MyTreeList.ShowRowDeleteConfirmation(context.VisibleIndex))" style="text-decoration: none;" href="javascript:void(0);"></a>
            </CellDisplayTemplate>
        </DxTreeListCommandColumn>
        <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 {
    ITreeList MyTreeList { get; set; }
    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);
    }
}

Blazor TreeList Editing Custom Command Buttons

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

See Also