Category / Section
How to skip editing for read-only colums in AddNewRow of WPF DataGrid (SfDataGrid)?
You can edit all the columns in AddNewRow including Read-Only columns as default in WPF DataGrid (SfDataGrid). But you can skip the editing for Read-Only columns by using CurrentCellBeginEdit event.
C#
this.grid.CurrentCellBeginEdit += grid_CurrentCellBeginEdit;
void grid_CurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs args)
{
var rowIndex = args.RowColumnIndex.RowIndex;
//If the rowindex in AddNewRowIndex, we need to validate whether the property is readonly or not.
if (this.grid.IsAddNewIndex(rowIndex))
{
//pdc - PropertyDescriptorCollection.
var pdc = this.grid.View.GetItemProperties();
//get the propertyinfo from PropertyDescriptorCollection.
var propertyInfo = pdc.Find(args.Column.MappingName, true);
//property is readonly you can cancel the editing of the cell.
if (propertyInfo.IsReadOnly)
{
args.Cancel = true;
}
}
}