{"record":{"id":"97fb68faf9563512","repo":"dotnet/wpf","slug":"sr-doesnotsupportmultipleselection","errorCode":null,"errorMessage":"SR.DoesNotSupportMultipleSelection","messagePattern":"SR\\.DoesNotSupportMultipleSelection","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListBox.cs","lineNumber":842,"sourceCode":"                if (ListboxItem.IsSelected (_hwnd, _item) && !_listBox.IsParentedByCombo())\n                {\n                    // if it is a combo, then always perform the selection otherwise the listbox won't disappear\n                    return;\n                }\n\n                bool multipleSelection = _listBox.IsMultipleSelection();\n\n                // object does not support multi-selection\n                if (!multipleSelection)\n                {\n                    IRawElementProviderSimple container = ((ISelectionItemProvider)this).SelectionContainer;\n                    bool selectionRequired = container != null ? ((ISelectionProvider)container).IsSelectionRequired : true;\n\n                    // For single selection containers that IsSelectionRequired == false and nothing is selected\n                    // an AddToSelection is valid.\n                    if (selectionRequired || _listBox.HasSelection())\n                    {\n                        throw new InvalidOperationException(SR.DoesNotSupportMultipleSelection);\n                    }\n                }\n\n                if (_listBox.IsParentedByCombo())\n                {\n                    // if this is a combo and the listbox is not displayed the selection will not stick, so \n                    // display the listbox before doing the select.\n                    if (((IExpandCollapseProvider)_listBox._parent).ExpandCollapseState == ExpandCollapseState.Collapsed)\n                    {\n                        ((IExpandCollapseProvider)_listBox._parent).Expand();\n                    }\n                }\n\n                // At this point we know: Item either supports multiple selection or nothing\n                // is selected in the list\n                // Try to select an item\n                if (!Select(multipleSelection))\n                {","sourceCodeStart":824,"sourceCodeEnd":860,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListBox.cs#L824-L860","documentation":"AddToSelection throws InvalidOperationException(SR.DoesNotSupportMultipleSelection) when the item's container requires a selection (IsSelectionRequired true) and already has one, or is otherwise a single-selection listbox — so adding another selected item would effectively create multiple selection, which the control does not support.","triggerScenarios":"Calling AddToSelection on an item of a single-selection listbox (IsMultipleSelection false) where a selection is required or a selection already exists and the item is not already selected.","commonSituations":"Treating a standard single-select ListBox as multi-select; assuming UIA AddToSelection behaves like click-with-ctrl on any list; migrating automation from HTML select multiple to Win32 listbox.","solutions":["Use Select instead of AddToSelection to replace the existing selection.","Verify SelectionPattern.CanSelectMultiple is true before calling AddToSelection.","If multi-select is needed, use a listbox with LBS_EXTENDEDSEL/LBS_MULTIPLESEL."],"exampleFix":"// before\nselectionItem.AddToSelection();\n// after\nif (!(listbox.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern).Current.CanSelectMultiple)\n{\n    selectionItem.Select(); // replace selection instead\n}\nelse\n{\n    selectionItem.AddToSelection();\n}","handlingStrategy":"validation","validationCode":"bool canAdd = listbox.GetCurrentPattern(SelectionPattern.Pattern) is SelectionPattern sp && sp.Current.CanSelectMultiple;\nif (!canAdd) { selectionItem.Select(); }","typeGuard":"bool SupportsMultiSelect(AutomationElement listbox) => (listbox.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern)?.Current.CanSelectMultiple == true;","tryCatchPattern":"try { selectionItem.AddToSelection(); }\ncatch (InvalidOperationException) { selectionItem.Select(); // fallback: replace selection }","preventionTips":["Always check SelectionPattern.CanSelectMultiple before AddToSelection","Treat single-selection listboxes with Select (replace) semantics","Test automation against both single and multi-select listboxes"],"tags":["uiautomation","single-selection","unsupported-operation"],"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"}