How can I define certain cells to be read-only? Also, how can entire rows be marked as read-only?
This should be data-driven and must be linked to the data only and not to the grid position. Thus, the proper cells must still be read-only if the user changes the sort order or inserts new rows that meet the criteria.
Hello,
The approach is to use the EditModeStarting Event of the XamDataGrid and set e.Cancel to true for the cells that are intended to be read only.
The problem is that EditModeStartingEventArgs only knows about the cell that is being edited. My application requires that the editable state is based on the value of another cell in the same row.
So, I would need something like this:
if (((e.Cell.Field.Name != "Status") || (e.Cell.Field.Name != "Notes")) && (e.Record.Cells["SystemGenerated"].Value == true)) { if (e.Cell.Record.IsAddRecord == false) { e.Cancel = true; } }
(e.Record is not available in EditModeStartingEventArgs.)
The Cell object exposes a Record property that will give you access to the DataRecord that the Cell belongs to so you could use e.Cell.Record.
Let me know if you have any questions with this matter.
It's working great now. Thanks!