// Adds this element to the selection void ISelectionItemProvider.AddToSelection() { // Make sure that the control is enabled if (!SafeNativeMethods.IsWindowEnabled(_hwnd)) { throw new ElementNotEnabledException(); } // simple case: object already selected if (WindowsListView.IsItemSelected(_hwnd, _item)) { return; } // object does not support multi-selection if (!WindowsListView.MultiSelected(_hwnd)) { IRawElementProviderSimple container = ((ISelectionItemProvider)this).SelectionContainer; bool selectionRequired = container != null ? ((ISelectionProvider)container).IsSelectionRequired : true; // For single selection containers that IsSelectionRequired == false and nothing is selected // an AddToSelection is valid. if (selectionRequired || WindowsListView.GetSelectedItemCount(_hwnd) > 0) { throw new InvalidOperationException(SR.Get(SRID.DoesNotSupportMultipleSelection)); } } // At this point we know: Item either supports multiple selection or nothing // is selected in the list // Try to select an item if (!WindowsListView.SelectItem(_hwnd, _item)) { throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed)); } }