{"record":{"id":"d9c046ae1519ec71","repo":"dotnet/wpf","slug":"sr-valuereadonly-windowslistviewitem","errorCode":null,"errorMessage":"SR.ValueReadonly","messagePattern":"SR\\.ValueReadonly","errorType":"exception","errorClass":"System.InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewItem.cs","lineNumber":751,"sourceCode":"                mask = NativeMethods.LVIF_GROUPID,\n                iItem = lvItem\n            };\n\n            if (XSendMessage.GetItem(hwnd, ref item))\n            {\n                return item.iGroupID;\n            }\n\n            return -1;\n        }\n\n        internal static void SetValue (string val, IntPtr hwnd, int item)\n        {\n            ArgumentNullException.ThrowIfNull(val);\n\n            if (!WindowsListView.ListViewEditable (hwnd))\n            {\n                throw new InvalidOperationException(SR.ValueReadonly);\n            }\n\n            Misc.SetFocus(hwnd);\n\n            // set focus to the item\n            WindowsListView.SetItemFocused (hwnd, item);\n\n            // retrieve edit window\n            IntPtr hwndEdit = WindowsListView.ListViewEditLabel (hwnd, item);\n\n            if (IntPtr.Zero == hwndEdit)\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n\n            // re-use editbox proxy to do the job\n            // Note: we will pass null and -1 for some of the parameters\n            // this is ok, since the only thing that matters to us is an ability to set the text","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewItem.cs#L733-L769","documentation":"InvalidOperationException(SR.ValueReadonly) is thrown by the internal static SetValue when the ListView does not have label editing enabled (ListViewEditable false). The ValuePattern edit is implemented by launching in-place label editing, so a non-editable list means its values are read-only.","triggerScenarios":"Calling SetValue (ValuePattern) on a ListView item whose control lacks LVS_EDITLABELS (ListViewEditable returns false).","commonSituations":"Default WinForms ListView (LabelEdit=false) automated with a SetValue call; test scripts assuming all list items are editable; app changed LabelEdit at runtime or across versions.","solutions":["Set ListView.LabelEdit = true on the target control to enable label editing.","Use BeginEdit/label-edit UI interaction instead of ValuePattern on non-editable lists.","Catch InvalidOperationException and treat the value as read-only.","Verify IsReadOnlyProperty on the ValuePattern before calling SetValue."],"exampleFix":"// before\nlistView1.Items[0].Text = \"x\"; // via UIA SetValue -> fails when LabelEdit is false\n// after\nlistView1.LabelEdit = true; // enables LVS_EDITLABELS so UIA SetValue works","handlingStrategy":"validation","validationCode":"var readOnly = (bool)item.CurrentPropertyValue(ValuePattern.IsReadOnlyProperty);\nif (readOnly) throw new InvalidOperationException(\"value is read-only (LabelEdit disabled)\");","typeGuard":null,"tryCatchPattern":"try { valuePattern.SetValue(text); }\ncatch (InvalidOperationException) { /* read-only: use app API or enable LabelEdit */ }","preventionTips":["Check ValuePattern.IsReadOnlyProperty before SetValue","Set ListView.LabelEdit = true in the app when editing is required","Do not assume list items are editable"],"tags":["uiautomation","winforms","listview","readonly","labeledit"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}