Skip to main content
All docs
V25.1
  • DxGrid.EditOnKeyPress Property

    In EditCell mode, specifies whether cell editing starts once a user begins typing a new value.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    [DefaultValue(false)]
    [Parameter]
    public bool EditOnKeyPress { get; set; }

    Property Value

    Type Default Description
    Boolean false

    true to start cell editing once a user begins typing a new value; otherwise, false.

    Remarks

    Note

    This property is in effect only if the EditMode property value is EditCell.

    In EditCell mode, the Grid component starts cell editing after a user clicks a cell or focuses it and presses Enter. Enable the EditOnKeyPress property to additionally enter edit mode once a user presses one of the following keys:

    • Alphabetic characters
    • Numerals
    • Punctuation marks
    • Special characters
    • Space
    • Backspace
    • Alt+Down[1]

    The following example allows users to enter edit mode once they start typing a new value:

    @using Microsoft.EntityFrameworkCore
    @inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
    @implements IDisposable
    
    <DxGrid Data="Data"
            KeyFieldName="EmployeeId"
            EditModelSaving="OnEditModelSaving"
            DataItemDeleting="OnDataItemDeleting"
            CustomizeEditModel="OnCustomizeEditModel"
            EditMode="GridEditMode.EditCell"
            EditOnKeyPress="true">
        <Columns>
            <DxGridCommandColumn EditButtonVisible="false" 
                                 CancelButtonVisible="false" 
                                 SaveButtonVisible="false" />
            <DxGridDataColumn FieldName="FirstName" />
            <DxGridDataColumn FieldName="LastName" />
            <DxGridDataColumn FieldName="Title" />
            <DxGridDataColumn FieldName="HireDate" />
        </Columns>
    </DxGrid>
    
    @code {
        IEnumerable<Employee> Data { get; set; }
        NorthwindContext Northwind { get; set; }
    
        protected override async Task OnInitializedAsync() {
            Northwind = NorthwindContextFactory.CreateDbContext();
            Data = await Northwind.Employees.ToListAsync();
        }
    
        void OnCustomizeEditModel(GridCustomizeEditModelEventArgs e) {
            if(e.IsNew) {
                var editModel = (Employee)e.EditModel;
                editModel.EmployeeId = Data.Max(x => x.EmployeeId) + 1;
            }
        }
    
        async Task OnEditModelSaving(GridEditModelSavingEventArgs e) {
            var editModel = (Employee)e.EditModel;
            if (e.IsNew)
                await Northwind.AddAsync(editModel);
            else
                e.CopyChangesToDataItem();
            // Post changes to the database.
            await Northwind.SaveChangesAsync();
            // Reload the entire Grid.
            Data = await Northwind.Employees.ToListAsync();
        }
    
        async Task OnDataItemDeleting(GridDataItemDeletingEventArgs e) {
            // Remove the data item from the database.
            Northwind.Remove(e.DataItem);
            await Northwind.SaveChangesAsync();
            // Reload the entire Grid.
            Data = await Northwind.Employees.ToListAsync();
        }
    
        public void Dispose() {
            Northwind?.Dispose();
        }
    }
    

    Implements

    Footnotes
    1. Available for combobox, date edit, and time edit DevExpress data editors.

    See Also