{"record":{"id":"5c503681f4b4da82","repo":"dotnet/wpf","slug":"elementnotenabledexception-windowslistviewitem","errorCode":null,"errorMessage":"ElementNotEnabledException","messagePattern":"ElementNotEnabledException","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewItem.cs","lineNumber":386,"sourceCode":"                        return CreateListViewSubItem (column);\n                    }\n                }\n            }\n            \n            return this;\n        }\n\n        #endregion\n\n        #region SelectionItem Pattern\n\n        // Selects this element\n        void ISelectionItemProvider.Select ()\n        {\n            // Make sure that the control is enabled\n            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            // simple case: object already selected - only works for single selection element\n            if (!WindowsListView.MultiSelected (_hwnd) && WindowsListView.IsItemSelected (_hwnd, _item))\n            {\n                return;\n            }\n\n            // Unselect all items.\n            WindowsListView.UnselectAll (_hwnd);\n\n            // Select the specified item.\n            if (!WindowsListView.SelectItem(_hwnd, _item))\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n        }\n","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewItem.cs#L368-L404","documentation":"ISelectionItemProvider.Select on a ListView item first verifies the owning Win32 window is enabled via IsWindowEnabled(_hwnd); if the control is disabled, it throws ElementNotEnabledException, the UIA-standard error for invoking a pattern on a disabled element. This tells the automation client that the Select request cannot be honored because the UI control does not accept user input right now.","triggerScenarios":"Calling the SelectionItemPattern.Select() (or Invoke/scroll-into-view variants that route here) on a ListViewItem whose ListView HWND is disabled - e.g. IsEnabled=false on the parent control, a modal dialog disabling the list, or the control disabled during a long operation.","commonSituations":"Test automation clicking items while the app shows a modal overlay; UIA scripts running against a form whose ListView is disabled pending data load; apps that disable lists during validation.","solutions":["Check the element's IsEnabled property (or IsWindowEnabled on the HWND) before calling Select and skip/queue the call when false.","Subscribe to UIA property-changed events for AutomationElement.IsEnabledProperty and only select once it becomes true.","If you own the app, enable the ListView before automation runs, or verify no modal state disables it.","Catch ElementNotEnabledException and retry with backoff until the control is enabled."],"exampleFix":"// before\n((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();\n\n// after\nif ((bool)item.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty))\n{\n    ((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();\n}","handlingStrategy":"validation","validationCode":"if (!(bool)item.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty))\n    throw new SkipOperationException(\"ListView disabled; cannot Select.\");","typeGuard":"bool IsEnabled(AutomationElement e) => e != null && (bool)e.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty);","tryCatchPattern":"try { selItem.Select(); }\ncatch (ElementNotEnabledException) { QueueForRetryWhenEnabled(item); }","preventionTips":["Always check element.IsEnabled before invoking any selection/invoke pattern","Subscribe to IsEnabledProperty change events to time automation actions","Ensure the app closes modal states that disable the ListView before running automation","Wrap all pattern calls in a helper that validates IsEnabled once"],"tags":["uiautomation","wpf","listview","disabled-control","elementnotenabled"],"backgroundTag":"element-not-enabled","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"}