How to disable the edit mode of AddNewRow in WPF SfDataGrid when AllowEditing is set as False ?
SfDataGrid allows you to disable the edit mode. You can do so by setting the AllowEditing property as False. Conversely, the AddNewRow is always editable, despite AllowEditing being false. This is because, AddNewRow allows you to add rows in the runtime to enter new records in the DataGrid control. On the other hand, you can disable the edit mode of AddNewRow in SfDataGrid, by handling the CurrentCellBeginEdit event. To set a particular column as read-only, you can specify the AllowEditing property of that column alone as False.
The following code example demonstrates how to disable the edit mode of a column in AddNewRow by handling CurrentCellBeginEdit event.
C#
this.dataGrid.CurrentCellBeginEdit += dataGrid_CurrentCellBeginEdit; void dataGrid_CurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs args) { if (this.dataGrid.IsAddNewIndex(args.RowColumnIndex.RowIndex)) { //First two columns in AddNewRow is made ReadOnly args.Cancel = !args.Column.AllowEditing; } }
The above code makes the selected columns read-only, by cancelling the editing feature of the columns, for which the AllowEditing property is set as false. Specifying AllowEditing as False for the grid disables the edit mode of the entire AddNewRow.
Screenshot:
Figure 1: Disable the edit mode of AddNewRow
Sample Link:
Conclusion
I hope you enjoyed learning about how to disable the edit mode of AddNewRow in WPF SfDataGrid when AllowEditing is set as False.
You can refer to our WPF DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF DataGrid example 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!