Skip to main content
All docs
V25.1
  • DxGrid.GetEditContext() Method

    Returns the edit context.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public EditContext GetEditContext()

    Returns

    Type Description
    EditContext

    The edit context if the Grid is being edited; otherwise, null.

    Remarks

    Call this method to obtain the Grid’s edit context. This context allows you to check whether the data item was modified and its field values are valid. If the Grid is not in edit mode, the GetEditContext method returns null.

    The following code snippet checks whether the edit row has unsaved changes:

    @inject NwindDataService NwindDataService
    
    <DxGrid @ref="Grid"
            Data="Data"
            KeyFieldName="EmployeeId"
            EditModelSaving="OnEditModelSaving"
            EditMode="GridEditMode.EditRow">
        <Columns>
            <DxGridCommandColumn />
            <DxGridDataColumn FieldName="FirstName" />
            <DxGridDataColumn FieldName="LastName" />
            <DxGridDataColumn FieldName="Title" />
            <DxGridDataColumn FieldName="HireDate" />
        </Columns>
    </DxGrid>
    
    @code {
        IGrid Grid { get; set; }
        IEnumerable<object> Data { get; set; }
        NorthwindContext Northwind { get; set; }
    
        async Task OnEditModelSaving(GridEditModelSavingEventArgs e) {
            if (Grid.GetEditContext().IsModified()) {
                // Save changes to the database
            }
        }
        // ...
    }
    

    Implements

    See Also