How to cancel the AddNewRow operation using single Esc key from edit mode in WPF DataGrid (SfDataGrid)?
You can cancel the editing operation when you press Esc Key in WPF DataGrid (SfDataGrid). The AddNewRow operation is cancelled when you pressed the Esc key twice while the AddNewRow cell is in editing mode.
Since when you press the Esc key in AddNewRow cell which is in edit mode below actions will happen,
1. At first key press, cell editing get canceled
2. At second key press AddNewRow operation is canceled.
On the other hand, you can cancel the AddNewRow operation in single Esc key by
override the GridSelectionController class and cancel the AddNewRow operation in HandleKeyDown event as like below code snippet.
C#
sfdatagrid.SelectionController = new GridSelectionControllerExt(sfdatagrid); public class GridSelectionControllerExt : GridSelectionController { public GridSelectionControllerExt(SfDataGrid sfdatagrid) : base(sfdatagrid) { } public override bool HandleKeyDown(KeyEventArgs args) { if (args.Key == Key.Escape) { if (this.DataGrid.View.IsAddingNew) { if (this.CurrentCellManager.CurrentCell.IsEditing) this.CurrentCellManager.EndEdit(true); this.DataGrid.GetAddNewRowController().CancelAddNew(); } } return base.HandleKeyDown(args); } }
Conclusion
I hope you enjoyed learning about how to get bounds of the GridControl in WPF application.
You can refer to our WPF Grid feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!