{"record":{"id":"f09a49f094b226fe","repo":"dotnet/wpf","slug":"elementnotenabledexception-windowslistviewgroup","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/WindowsListViewGroup.cs","lineNumber":406,"sourceCode":"        }\n\n        int IGridProvider.ColumnCount\n        {\n            get\n            {\n                return GetColumnCount (_hwnd, ID);\n            }\n        }\n\n        #endregion Grid Pattern\n\n        #region ExpandCollapse Pattern\n\n        private void CheckControlEnabled()\n        {\n            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n        }\n\n        void IExpandCollapseProvider.Expand()\n        {\n            ExpandOrCollapse(false);\n        }\n\n        private bool IsCollapsed()\n        {\n            return IsCollapsed(_hwnd, _groupID);\n        }\n\n        internal static bool IsCollapsed(IntPtr hwnd, int groupID)\n        {\n            bool isCollapsed = false;\n            NativeMethods.LVGROUP group = new NativeMethods.LVGROUP();\n            group.Init(Marshal.SizeOf(typeof(NativeMethods.LVGROUP)));","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewGroup.cs#L388-L424","documentation":"WindowsListViewGroup.CheckControlEnabled throws ElementNotEnabledException (no custom message) when SafeNativeMethods.IsWindowEnabled(_hwnd) reports the underlying ListView window is disabled. It is called at the start of ExpandOrCollapse, so Expand()/Collapse() on a disabled control is rejected as required by the UIA ExpandCollapse pattern contract.","triggerScenarios":"Calling ExpandCollapsePattern.Expand() or Collapse() on a ListView group whose hosting ListView window is disabled (IsWindowEnabled == false), e.g. while a modal dialog blocks the window.","commonSituations":"Automation run during a modal dialog, a disabled parent form, or the app intentionally disabling the list; test scripts that don't check IsEnabled before interacting.","solutions":["Check the element's IsEnabled property (or IsWindowEnabled) before invoking Expand/Collapse and skip or wait.","Wait for the blocking modal window to close and the control to re-enable, then retry.","Catch ElementNotEnabledException and record the control as non-interactive instead of failing the run."],"exampleFix":"// before\nexpandPattern.Expand();\n// after\nif (element.Current.IsEnabled) expandPattern.Expand();\nelse WaitForEnabled(element, timeout);","handlingStrategy":"validation","validationCode":"if (!element.Current.IsEnabled) { WaitForEnabled(element, TimeSpan.FromSeconds(5)); }","typeGuard":null,"tryCatchPattern":"try { expandPattern.Expand(); }\ncatch (ElementNotEnabledException) { log.Info(\"ListView disabled; skipping group expand\"); }","preventionTips":["Check IsEnabled before every pattern invocation on list controls.","Detect and dismiss modal dialogs before automating the blocked window."],"tags":["uiautomation","disabled-control","expand-collapse"],"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"}