{"record":{"id":"0f4730c36ed548f2","repo":"dotnet/wpf","slug":"sr-datagrid-columnisreadonly","errorCode":null,"errorMessage":"SR.DataGrid_ColumnIsReadOnly","messagePattern":"SR\\.DataGrid_ColumnIsReadOnly","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridCellItemAutomationPeer.cs","lineNumber":753,"sourceCode":"        }\n\n        #endregion\n\n        #region IValueProvider\n\n        bool IValueProvider.IsReadOnly\n        {\n            get\n            {\n                return _column.IsReadOnly;\n            }\n        }\n\n        void IValueProvider.SetValue(string value)\n        {\n            if (_column.IsReadOnly)\n            {\n                throw new InvalidOperationException(SR.DataGrid_ColumnIsReadOnly);\n            }\n            if (this.OwningDataGrid != null)\n            {\n                OwningDataGrid.SetCellAutomationValue(Item, _column, value);\n            }\n        }\n\n        string IValueProvider.Value\n        {\n            get\n            {\n                if (this.OwningDataGrid != null)\n                {\n                    return OwningDataGrid.GetCellAutomationValue(Item, _column);\n                }\n                else\n                {\n                    return null;","sourceCodeStart":735,"sourceCodeEnd":771,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridCellItemAutomationPeer.cs#L735-L771","documentation":"DataGridCellItemAutomationPeer's IValueProvider.SetValue sets a cell's value via OwningDataGrid.SetCellAutomationValue. If the column is read-only (DataGridColumn.IsReadOnly == true), the value cannot be written, so the peer throws InvalidOperationException with SR.DataGrid_ColumnIsReadOnly before attempting the set.","triggerScenarios":"An automation client calls SetValue(string) (IValueProvider) on a cell whose DataGridColumn.IsReadOnly is true — including columns made read-only via binding, DataGrid.IsReadOnly, or read-only row (NewItemPlaceholder).","commonSituations":"UIA data-entry tests against DataGrids where some columns are intentionally read-only (e.g. computed or key columns); automated form fillers; apps that toggle IsReadOnly at runtime based on permissions.","solutions":["Check column.IsReadOnly before calling SetValue and skip or use a different editable column.","Make the column editable if the business scenario requires programmatic updates (set IsReadOnly=false or remove the read-only binding).","Catch InvalidOperationException and surface a clear message that the column is not editable.","Update test data to only target writable columns."],"exampleFix":"// before\n((IValueProvider)cellPattern).SetValue(\"42\");\n\n// after\nif (!column.IsReadOnly)\n    ((IValueProvider)cellPattern).SetValue(\"42\");","handlingStrategy":"validation","validationCode":"if (!column.IsReadOnly && !dataGrid.IsReadOnly) valueProvider.SetValue(value);","typeGuard":"bool IsWritable(DataGridColumn c, DataGrid g) => c != null && !c.IsReadOnly && g != null && !g.IsReadOnly;","tryCatchPattern":"try { valueProvider.SetValue(value); } catch (InvalidOperationException ex) { /* surface read-only message */ }","preventionTips":["Check column.IsReadOnly before SetValue","Keep test data targets on editable columns","Account for runtime permission-driven IsReadOnly changes"],"tags":["wpf","automation","datagrid","value-provider","read-only"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}