Training
Module
Improve how forms and validation work in Blazor web apps - Training
Learn how to use DOM events, forms, and validation in a Blazor app
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The DataGrid control supports cell and row editing functionality. By default, you can edit items directly in the DataGrid. The user can enter edit mode in a cell by pressing F2 key or double tapping on a cell. Alternatively, you can set the DataGridColumn.IsReadOnly property to true to disable editing in specific columns of the DataGrid.
<controls:DataGrid BeginningEdit="dg_Editing" CellEditEnding="dg_CellEditEnding" RowEditEnding="dg_RowEditEnding" />
A cell-level edit is committed when you move to another cell in the same row. All edits in a row are committed when you press ENTER or move to another row.
To guarantee that edits can be committed and canceled correctly, the objects in the DataGrid must implement the IEditableObject interface.
The following table lists the methods and events supported by DataGrid for cell and row editing functionality.
Type | Name | Description |
---|---|---|
Method | PreparingCellForEdit | Occurs when a cell in a DataGridTemplateColumn enters editing mode. This event does not occur for cells in other column types. |
Method | PrepareCellForEdit | Occurs when a cell in a column derived from DataGridColumn enters editing mode. This event does not occur for cells of type DataGridTemplateColumn. |
Method | BeginEdit | Causes the data grid to enter editing mode for the current cell and current row, unless the data grid is already in editing mode. |
Method | CommitEdit | Causes the data grid to commit the current edit to the data source, and optionally exit editing mode. |
Method | CancelEdit | Causes the data grid to cancel the current edit, restore the original value, and exit editing mode. |
Event | BeginningEdit | Occurs before a cell or row enters editing mode. This event lets you perform special processing before a cell or row enters editing mode. |
Event | CellEditEnding | Occurs when a cell edit is ending. You can cancel this event by setting the Cancel property of the e argument to true in the event handler. If this event is not canceled, the specified EditAction will be performed to commit or cancel the edit. After the edit has been successfully committed or canceled, the CellEditEnded event occurs. |
Event | CellEditEnded | Occurs when a cell edit has been committed or canceled. |
Event | RowEditEnding | Occurs when a row edit is ending. You can cancel this event by setting the Cancel property of the e argument to true in the event handler. If this event is not canceled, the specified EditAction will be performed to commit or cancel the edit. After the edit has been successfully committed or canceled, the RowEditEnded event occurs. |
Event | RowEditEnded | Occurs when a row edit has been committed or canceled. |
DataGrid control supports input validation through INotifyDataErrorInfo in your DataModel or ViewModel. Implement data validation logic by implementing DataErrorsChangedEventArgs, HasErrors and GetErrors methods. The DataGrid control automatically shows the error UI in the editing cell/row when the error conditions are met.
See DataGrid Sample for an example of how to handle input validation in the DataGrid control.
Training
Module
Improve how forms and validation work in Blazor web apps - Training
Learn how to use DOM events, forms, and validation in a Blazor app
Documentation
Keyboard navigation and selection concepts in the DataGrid control - Windows Community Toolkit
Guidance document that shows how to use keyboard to navigate the DataGrid control and selection models
Customize the DataGrid control - Windows Community Toolkit
Guidance document that shows how to use the different formatting options to customize the look and feel of the DataGrid control
Sizing Options in the DataGrid Control - WPF .NET Framework
Learn how to set individual rows and columns in the Windows Presentation Foundation DataGrid control to size to their contents or to specific values.