{"record":{"id":"de53e794395008f2","repo":"dotnet/wpf","slug":"sr-operationcannotbeperformed-windowslistviewitemcheckbox","errorCode":null,"errorMessage":"SR.OperationCannotBePerformed","messagePattern":"SR\\.OperationCannotBePerformed","errorType":"exception","errorClass":"System.InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewItemCheckBox.cs","lineNumber":218,"sourceCode":"                \n        //------------------------------------------------------\n        //\n        //  Private Methods\n        //\n        //------------------------------------------------------\n\n        #region Private Methods\n        \n        // retrieve current ToggleState\n        private ToggleState GetToggleState ()\n        {\n            ListViewItem.CheckState current = (ListViewItem.CheckState) WindowsListView.GetCheckedState (_hwnd, _listviewItem);\n\n            switch (current)\n            {\n                case ListViewItem.CheckState.NoCheckbox :\n                    {\n                        throw new InvalidOperationException(SR.OperationCannotBePerformed);\n                    }\n\n                case ListViewItem.CheckState.Checked :\n                    {\n                        return ToggleState.On;\n                    }\n\n                case ListViewItem.CheckState.Unchecked :\n                    {\n                        return ToggleState.Off;\n                    }\n            }\n\n            // developer defined custom values which cannot be interpret outside of the app's scope\n            return ToggleState.Indeterminate;\n        }\n        \n        private void Toggle()","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewItemCheckBox.cs#L200-L236","documentation":"This InvalidOperationException(SR.OperationCannotBePerformed) is thrown by the CheckBox ListViewItem proxy's GetToggleState when the underlying item has no checkbox (GetCheckedState returns CheckState.NoCheckbox). A toggle state cannot exist for an item without a checkbox, so the provider reports the operation as invalid.","triggerScenarios":"Reading ToggleStateProperty (via TogglePattern/state query) on a CheckBox-style ListView item whose row has no checkbox — e.g. checkboxes disabled on the list (LVS_EX_CHECKBOXES removed) or a plain item in the same list.","commonSituations":"Apps toggling CheckBoxes on/off at runtime while automation still holds old element references; mixed lists where some items lack checkboxes; UIA clients caching TogglePattern for elements whose checkbox was removed.","solutions":["Check that the ListView has checkbox style (LVS_EX_CHECKBOXES via LVM_GETEXTENDEDLISTVIEWSTYLE) before reading ToggleState.","Refresh the automation element after the app changes checkbox styles.","Catch InvalidOperationException and treat the item as non-toggleable (TogglePattern not supported).","Re-query supported patterns; avoid caching patterns across UI state changes."],"exampleFix":"// before\nvar state = item.GetCurrentPropertyValue(TogglePattern.ToggleStateProperty);\n// after\nvar style = (int)SendMessage(listViewHandle, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);\nif ((style & LVS_EX_CHECKBOXES) != 0)\n{\n    var state = item.GetCurrentPropertyValue(TogglePattern.ToggleStateProperty);\n}\nelse\n{\n    // item has no checkbox; skip toggle-state reads\n}","handlingStrategy":"validation","validationCode":"var style = (int)SendMessage(listHandle, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);\nbool hasCheckBoxes = (style & LVS_EX_CHECKBOXES) != 0;","typeGuard":null,"tryCatchPattern":"try { state = togglePattern.CurrentState; }\ncatch (InvalidOperationException) { /* item has no checkbox: not toggleable */ }","preventionTips":["Confirm LVS_EX_CHECKBOXES before reading ToggleState","Refresh elements after checkbox style changes","Do not cache TogglePattern across UI state changes"],"tags":["uiautomation","winforms","listview","checkbox","toggle"],"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"}