Editing in WinUI Data Grid
SfDataGrid provides support for editing and it can be enabled or disabled by setting SfDataGrid.AllowEditing property.
<dataGrid:SfDataGrid x:Name="sfDataGrid"
AllowEditing="True"
AutoGenerateColumns="True"
ItemsSource="{Binding Employees}"/>sfDataGrid.AllowEditing = true;You can enable or disable editing for particular column by setting GridColumn.AllowEditing property.
<syncfusion:GridTextColumn HeaderText="Employee ID" MappingName="ID" AllowEditing="True"/>sfDataGrid.Columns["ID"].AllowEditing = true;GridColumn.AllowEditing takes higher priority than SfDataGrid.AllowEditing.

It is mandatory to set the NavigationMode to Cell to enable CurrentCell navigation and editing.
Entering into edit mode
You can enter into edit mode by pressing F2 key or clicking (touch also supported) the cell. You can allow users to edit the cell in single click (OnTap) or double click (OnDoubleTap) by setting EditTrigger property. Typing a printable character on the current cell also begins editing. For more information, refer to Non-Alphanumeric Key Type-to-Edit.
<dataGrid:SfDataGrid x:Name="sfDataGrid"
AllowEditing="True"
EditTrigger="OnDoubleTap"
AutoGenerateColumns="True"
ItemsSource="{Binding Employees}"/>sfDataGrid.EditTrigger = EditTrigger.OnDoubleTap;Non-Alphanumeric Key Type-to-Edit
When a cell is the current cell, typing a printable character, including non-alphanumeric characters such as @, #, $, %, &, - and ., begins editing that cell. There is no separate property for this behavior. Type-to-edit is available when editing is enabled by AllowEditing and NavigationMode is set to Cell.
<dataGrid:SfDataGrid x:Name="sfDataGrid"
AllowEditing="True"
NavigationMode="Cell"
AutoGenerateColumns="False"
ItemsSource="{Binding Employees}">
<dataGrid:SfDataGrid.Columns>
<dataGrid:GridTextColumn HeaderText="Employee Name" MappingName="Name" />
<dataGrid:GridNumericColumn HeaderText="Salary" MappingName="Salary" />
</dataGrid:SfDataGrid.Columns>
</dataGrid:SfDataGrid>using Syncfusion.UI.Xaml.Grids;
sfDataGrid.AllowEditing = true;
sfDataGrid.NavigationMode = NavigationMode.Cell;
The result depends on the column type of the current cell,
- GridTextColumn – the typed character replaces the existing value, and the cursor is placed after it. EditorSelectionBehavior does not affect this case.
-
GridNumericColumn – only the digits 0 to 9 are applied and replace the existing value. Any other character, such as
-,.or a symbol, opens the editor with the existing value. -
GridUnBoundColumn – with the default text editor, the typed character replaces the existing value. With
EditTemplateorEditTemplateSelector, editing does not begin by typing. - Other editable columns – the editor opens with the existing value.
- Non-editable columns – editing does not begin.
Cases that do not begin editing
Typing does not begin editing in the following cases,
- A control character, a white-space character such as Space, or a surrogate character such as an emoji is typed.
- Ctrl alone or Alt alone is pressed with the key. Ctrl + Alt (AltGr) is treated as text, so characters from localized keyboards begin editing.
-
NavigationMode is not set to
Cell. - The cell is already in edit mode.
- The cell is read-only or non-editable.
- The current cell belongs to a template column.
- The edit is canceled in the CurrentCellBeginEdit event. The cell remains unchanged and the typed character is not applied.
The
CurrentCellBeginEditevent does not distinguish editing started by typing from editing started by F2 or a click. Canceling the event cancels all of them.
Cursor placement
When the cell enters into edit mode, cursor is placed based on EditorSelectionBehavior property.
SelectAll – selects the text of edit element loaded inside cell.
MoveLast – places the cursor at the last of edit element loaded inside cell.
<dataGrid:SfDataGrid x:Name="sfDataGrid"
AllowEditing="True"
EditorSelectionBehavior="MoveLast"
AutoGenerateColumns="True"
ItemsSource="{Binding Employees}"/>sfDataGrid.EditorSelectionBehavior = EditorSelectionBehavior.MoveLast;
Retain editing on lost focus
The editing of current cell will be ended by default while the focus is moving from DataGrid to another control. You can set the LostFocusBehavior property to LostFocusBehavior.Default if you want to retain the editing of the current cell even when focus is moved to another control.
<dataGrid:SfDataGrid x:Name="sfDataGrid"
AllowEditing="True"
AutoGenerateColumns="True"
LostFocusBehavior="Default"
ItemsSource="{Binding Employees}"/>sfDataGrid.LostFocusBehavior = LostFocusBehavior.Default;Events
SfDataGrid triggers the following events during editing.
CurrentCellBeginEdit Event
CurrentCellBeginEdit event occurs when the CurrentCell enter into edit mode. CurrentCellBeginEditEventArgs has following members which provides information for CurrentCellBeginEdit event.
-
Cancel: When set to ‘true’, the event is canceled and the
CurrentCelldoes not enter into the edit mode. -
RowColumnIndex: Gets the current row column index of the DataGrid.
-
Column: Gets the Grid Column of the SfDataGrid.
this.sfDataGrid.CurrentCellBeginEdit += SfDataGrid_CurrentCellBeginEdit;
private void SfDataGrid_CurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs e)
{
}CurrentCellEndEdit Event
CurrentCellEndEdit event occurs when the CurrentCell exits the edit mode. CurrentCellEndEditEventArgs has following members which provides information for CurrentCellEndEdit event.
- RowColumnIndex: Gets the value for the current row column index.
this.sfDataGrid.CurrentCellEndEdit += SfDataGrid_CurrentCellEndEdit;
private void SfDataGrid_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e)
{
}CurrentCellValueChanged Event
CurrentCellValueChanged event occurs whenever a value changes in GridColumn’s that supports editing.
CurrentCellValueChangedEventArgs has following members which provides information for CurrentCellValueChanged event.
-
Column: Gets the Grid Column of the SfDataGrid.
-
RowColumnIndex: Gets the value of the current RowColumnIndex.
-
Record: Gets the record of the corresponding cell value changes.
this.sfDataGrid.CurrentCellValueChanged += SfDataGrid_CurrentCellValueChanged;
private void SfDataGrid_CurrentCellValueChanged(object sender, CurrentCellValueChangedEventArgs e)
{
}For GridComboBoxColumn, you have to use the CurrentCellDropDownSelectionChanged event.
CurrentCellDropDownSelectionChanged Event
CurrentCellDropDownSelectionChanged event occurs whenever the SelectedItem of GridComboBoxColumn column changed.
CurrentCellDropDownSelectionChangedEventArgs has following members which provides information for CurrentCellDropDownSelectionChanged event.
-
RowColumnIndex – Gets the RowColumnIndex of the corresponding item that were selected from the drop-down control.
-
SelectedIndex – Gets the index of the corresponding item that were selected from the drop-down control.
-
SelectedItem – Gets the data item that were selected from the drop-down control.
this.sfDataGrid.CurrentCellDropDownSelectionChanged += SfDataGrid_CurrentCellDropDownSelectionChanged;
private void SfDataGrid_CurrentCellDropDownSelectionChanged(object sender, CurrentCellDropDownSelectionChangedEventArgs e)
{
}CellTapped Event
CellTapped event occurs when the user clicks or touches the Cell in SfDataGrid with GridCellTappedEventArgs. CellTapped event does not occur for the non-selectable cells. The GridCellTappedEventArgs has following members which provides information for CellTapped event.
-
Column - Gets the GridColumn of the tapped cell.
-
Record - Gets the data context of the tapped cell.
-
RowColumnIndex - Gets the RowColumnIndex of the tapped cell.
-
PointerDeviceType - Gets the device type that associated with the event.
-
OriginalSender - Gets the original reporting source that raised the event.
<dataGrid:SfDataGrid x:Name="sfDataGrid"
CellTapped="SfDataGrid_CellTapped"
AutoGenerateColumns="True"
ItemsSource="{Binding Employees}"/>this.sfDataGrid.CellTapped += SfDataGrid_CellTapped;
private void SfDataGrid_CellTapped(object sender, GridCellTappedEventArgs e)
{
}CellDoubleTapped Event
CellDoubleTapped event occurs when the user double clicks or double taps the GridCell in SfDataGrid with GridCellDoubleTappedEventArgs. CellDoubleTapped event does not occur for non-selectable cells. GridCellDoubleTappedEventArgs has following members which provides information for CellDoubleTapped event.
-
Column - Gets the GridColumn of the double tapped cell.
-
Record - Gets the data context of the double tapped cell.
-
RowColumnIndex - Gets the RowColumnIndex of the double tapped cell.
-
PointerDeviceType - Gets the device type that associated with the event.
-
OriginalSender - Gets the original reporting source that raised the event
<dataGrid:SfDataGrid x:Name="sfDataGrid"
CellDoubleTapped="SfDataGrid_CellDoubleTapped"
AutoGenerateColumns="True"
ItemsSource="{Binding Employees}"/>this.sfDataGrid.CellDoubleTapped += SfDataGrid_CellDoubleTapped;
private void SfDataGrid_CellDoubleTapped(object sender, GridCellDoubleTappedEventArgs e)
{
}Programmatically edit the cell
BeginEdit
SfDataGrid allows you to edit the cell programmatically by calling the BeginEdit method. Initially the CurrentCell need to set before calling the BeginEdit method when the CurrentCell value is null.
//Add this namespace to access the RowColumnIndex structure type in SfDataGrid
using Syncfusion.UI.Xaml.Grids.ScrollAxis;
this.sfDataGrid.Loaded += SfDataGrid_Loaded;
private void SfDataGrid_Loaded(object sender, RoutedEventArgs e)
{
RowColumnIndex rowColumnIndex = new RowColumnIndex(3, 2);
this.sfDataGrid.MoveCurrentCell(rowColumnIndex);
this.sfDataGrid.SelectionController.CurrentCellManager.BeginEdit();
}EndEdit
You can call the EndEdit method to programmatically end edit.
this.sfDataGrid.SelectionController.CurrentCellManager.EndEdit();CancelEdit
You can use the CurrentCellBeginEdit event to cancel the editing operation for the corresponding cell.
//Add this namespace to access the RowColumnIndex structure type in SfDataGrid
using Syncfusion.UI.Xaml.Grids.ScrollAxis;
this.sfDataGrid.CurrentCellBeginEdit += SfDataGrid_CurrentCellBeginEdit;
private void SfDataGrid_CurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs e)
{
var recordIndex = this.sfDataGrid.ResolveToRecordIndex(e.RowColumnIndex.RowIndex);
var columnIndex = this.sfDataGrid.ResolveToGridVisibleColumnIndex(e.RowColumnIndex.ColumnIndex);
var mappingName = this.sfDataGrid.Columns[columnIndex].MappingName;
var record = this.sfDataGrid.View.Records.GetItemAt(recordIndex);
var cellValue = this.sfDataGrid.View.GetPropertyAccessProvider().GetValue(record, mappingName);
if (e.RowColumnIndex == new RowColumnIndex(3, 2))
e.Cancel = true;
}