Skip to main content

DevExpress v24.1 Update — Your Feedback Matters

Our What's New in v24.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DxGrid.IsEditing() Method

Returns whether the Grid is being edited.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public bool IsEditing()

#Returns

Type Description
Boolean

true if the Grid is being edited; otherwise, false.

#Remarks

Call the IsEditing method to check whether the Grid is in edit mode. The IsEditingRow(Int32) method allows you to identify whether the specified row is being edited. The IsEditingNewRow() method returns whether a new or existing row is in edit mode.

Tip

For information on how to enable data editing, refer to the following topic: Editing and Validation in Blazor Grid.

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

<DxGrid Data="GridDataSource"
        EditModelSaving="OnEditModelSaving"
        KeyFieldName="EmployeeId"
        EditMode="GridEditMode.EditRow"
        @ref="MyGrid">
    <Columns>
        <DxGridCommandColumn DeleteButtonVisible="false" />
        <DxGridDataColumn FieldName="FirstName" />
        <DxGridDataColumn FieldName="LastName" />
        <DxGridDataColumn FieldName="Title" />
        <DxGridDataColumn FieldName="HireDate" />
    </Columns>
</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;
        // Assign changes from the edit model to the data item.
        if (e.IsNew)
            await Northwind.AddAsync(editModel);
        else
            e.CopyChangesToDataItem();
        // Post changes to the database.
        await Northwind.SaveChangesAsync();
        // Reload the entire Grid.
        GridDataSource = await Northwind.Employees.ToListAsync();
    }

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

#Implements

See Also