{"record":{"id":"2de67c803bb4506e","repo":"dotnet/wpf","slug":"elementnotenabledexception-windowslistviewsubitem","errorCode":null,"errorMessage":"ElementNotEnabledException","messagePattern":"ElementNotEnabledException","errorType":"exception","errorClass":"System.Windows.Automation.ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewSubItem.cs","lineNumber":219,"sourceCode":"        }\n\n        // Sets the focus to this item.\n        internal override bool SetFocus()\n        {\n            // Set the item's state to focused.\n            return WindowsListView.SetItemFocused (_hwnd, this._itemParent);\n        }\n\n        #endregion ProxySimple Interface\n\n        #region Value Pattern\n\n        void IValueProvider.SetValue (string val)\n        {\n            // Make sure that the control is enabled\n            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            ListViewItem.SetValue (val, _hwnd, _itemParent);\n        }\n\n        // Request to get the value that this UI element is representing as a string\n        string IValueProvider.Value\n        {\n            get\n            {\n                return ListViewItem.GetText (_hwnd, _itemParent, _item);\n            }\n        }\n\n        bool IValueProvider.IsReadOnly\n        {\n            get\n            {","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewSubItem.cs#L201-L237","documentation":"IValueProvider.SetValue on a list-view sub-item (WindowsListViewSubItem) throws ElementNotEnabledException when the owning list-view HWND is disabled. The UIA Value contract forbids setting a value on a disabled element, so the provider checks SafeNativeMethods.IsWindowEnabled(_hwnd) before delegating to ListViewItem.SetValue. IsWindowEnabled also returns false when any ancestor window is disabled.","triggerScenarios":"Calling ValuePattern.SetValue(string) on a list-view sub-item while the ListView window (or one of its parents) is disabled via WS_DISABLED, e.g. during a modal operation or after EnableWindow(hwnd, false).","commonSituations":"Editing list-view labels in tests while the dialog is disabled awaiting a background task; applications disabling the ListView during updates; automation running against a frozen UI; parent-disabled windows making children report disabled.","solutions":["Check the element's IsEnabled property (or IsWindowEnabled on the ListView HWND) before calling SetValue","Wait for the application to re-enable the window (end of modal/busy state) then retry SetValue","Re-enable the ListView in the application code before performing programmatic edits","Catch ElementNotEnabledException and report the edit as blocked because the control is disabled"],"exampleFix":"// before\n((ValuePattern)subItem.GetCurrentPattern(ValuePattern.Pattern)).SetValue(\"new text\");\n\n// after\nvar pattern = (ValuePattern)subItem.GetCurrentPattern(ValuePattern.Pattern);\nif (subItem.Current.IsEnabled)\n{\n    pattern.SetValue(\"new text\");\n}","handlingStrategy":"validation","validationCode":"// C#: check enabled state before editing a list-view sub-item\nAutomationElement subItem = /* ... */;\nif (!subItem.Current.IsEnabled)\n    throw new SkipRetryException(\"ListView window is disabled; cannot set value\");\n((ValuePattern)subItem.GetCurrentPattern(ValuePattern.Pattern)).SetValue(\"new text\");","typeGuard":"bool IsEditable(AutomationElement el) =>\n    el.Current.IsEnabled && !el.Current.IsPassword && el.TryGetCurrentPattern(ValuePattern.Pattern, out _);","tryCatchPattern":"try\n{\n    ((ValuePattern)el.GetCurrentPattern(ValuePattern.Pattern)).SetValue(text);\n}\ncatch (ElementNotEnabledException)\n{\n    // window (or an ancestor) is disabled; defer until re-enabled\n}","preventionTips":["Check IsEnabled before every ValuePattern.SetValue call","In tests, wait for the window to leave modal/disabled state before editing","Check ancestor windows too: a disabled parent disables children (IsWindowEnabled semantics)","Verify ListViewLabelEdit support in the app before attempting sub-item edits"],"tags":["uiautomation","valuepattern","disabled-control","listview"],"backgroundTag":"invalid-state-transition","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"}