Skip to main content
A newer version of this page is available. .

DxGrid.IsEditingRow(Int32) Method

Returns whether the specified Grid row is currently being edited.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public bool IsEditingRow(
    int visibleIndex
)

Parameters

Name Type Description
visibleIndex Int32

The row’s visible index.

Returns

Type Description
Boolean

true if the specified row is currently being edited; otherwise, false.

Remarks

The Grid allows users to edit its data either by using the edit form or by showing the edit form in a pop-up window.

Tip

For information on how to enable data editing, refer to the following topic: Edit Data and Validate Input.

Call the IsEditingRow method to identify whether the edit form is displayed for the specified row. You can also call the IsEditingNewRow() method to check whether the edit form is displayed for a new row. The IsEditing() method returns whether any Grid row is currently being edited.

@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable

<DxGrid Data="GridDataSource"
        EditModelSaving="OnEditModelSaving"
        KeyFieldName="EmployeeId"
        @ref="MyGrid">
    <Columns>
        <DxGridCommandColumn DeleteButtonVisible="false" />
        <DxGridDataColumn FieldName="FirstName" />
        <DxGridDataColumn FieldName="LastName" />
        <DxGridDataColumn FieldName="Title" />
        <DxGridDataColumn FieldName="HireDate" />
    </Columns>
    <EditFormTemplate Context="editFormContext">
        @{
            var employee = (Employee)editFormContext.EditModel;
        }
        <DxFormLayout>
            <DxFormLayoutItem Caption="First Name:">
                <DxTextBox @bind-Text="@employee.FirstName" />
            </DxFormLayoutItem>
            <DxFormLayoutItem Caption="Last Name:">
                <DxTextBox @bind-Text="@employee.LastName" />
            </DxFormLayoutItem>
            <DxFormLayoutItem Caption="Title:">
                <DxTextBox @bind-Text="@employee.Title" />
            </DxFormLayoutItem>
            <DxFormLayoutItem Caption="Hire Date:">
                <DxDateEdit @bind-Date="@employee.HireDate" />
            </DxFormLayoutItem>
        </DxFormLayout>
    </EditFormTemplate>
</DxGrid>

<br />
<DxButton Click="() => IsEditingInfo = MyGrid.IsEditing()">Is Editing</DxButton>
<DxButton Click="() => IsditingFirstRowEInfo = MyGrid.IsEditingRow(0)">Is Editing First Row</DxButton>
<DxButton Click="() => IsEditingNewRowInfo = MyGrid.IsEditingNewRow()">Is Editing New Row</DxButton>

<div><b>Is Editing</b>: @IsEditingInfo</div>
<div><b>Is Editing First Row</b>: @IsditingFirstRowEInfo</div>
<div><b>Is Editing New Row</b>: @IsEditingNewRowInfo</div>

@code {
    IEnumerable<object> GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    object SelectedDataItem { get; set; }
    IGrid MyGrid { get; set; }
    bool IsEditingInfo { get; set; }
    bool IsditingFirstRowEInfo { get; set; }
    bool IsEditingNewRowInfo { get; set; }

    protected override async Task OnInitializedAsync() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        GridDataSource = await Northwind.Employees.ToListAsync();
        SelectedDataItem = GridDataSource.FirstOrDefault();
    }

    async Task OnEditModelSaving(GridEditModelSavingEventArgs e) {
        var editModel = (Employee)e.EditModel;
        var dataItem = e.IsNew ? new Employee() : Northwind.Employees.Find(editModel.EmployeeId);
        if (dataItem != null) {
            dataItem.FirstName = editModel.FirstName;
            dataItem.LastName = editModel.LastName;
            dataItem.Title = editModel.Title;
            dataItem.HireDate = editModel.HireDate;
            if (e.IsNew)
                await Northwind.AddAsync(dataItem);
            await Northwind.SaveChangesAsync();
            GridDataSource = await Northwind.Employees.ToListAsync();
        }
    }

    public void Dispose() {
        Northwind?.Dispose();
    }
}

Implements

See Also