dotnet/wpf · error · ElementNotEnabledException
ElementNotEnabledException
Error message
ElementNotEnabledException
What it means
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.
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.
Example fix
// before
((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();
// after
if ((bool)item.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty))
{
((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();
} Defensive patterns
Strategy: validation
Validate before calling
if (!(bool)item.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty))
throw new SkipOperationException("ListView disabled; cannot Select."); Type guard
bool IsEnabled(AutomationElement e) => e != null && (bool)e.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty);
Try / catch
try { selItem.Select(); }
catch (ElementNotEnabledException) { QueueForRetryWhenEnabled(item); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Element is not enabled.
- ElementNotEnabledException
- SR.DoesNotSupportMultipleSelection
- SR.OperationCannotBePerformed
- SR.OperationCannotBePerformed
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5c503681f4b4da82.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewItem.cs:386
return CreateListViewSubItem (column);
}
}
}
return this;
}
#endregion
#region SelectionItem Pattern
// Selects this element
void ISelectionItemProvider.Select ()
{
// Make sure that the control is enabled
if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
{
throw new ElementNotEnabledException();
}
// simple case: object already selected - only works for single selection element
if (!WindowsListView.MultiSelected (_hwnd) && WindowsListView.IsItemSelected (_hwnd, _item))
{
return;
}
// Unselect all items.
WindowsListView.UnselectAll (_hwnd);
// Select the specified item.
if (!WindowsListView.SelectItem(_hwnd, _item))
{
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
}
View on GitHub (pinned to 81131a70a4)