// Removes this element from the selection
        void ISelectionItemProvider.RemoveFromSelection()
        {
            // Make sure that the control is enabled
            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
            {
                throw new ElementNotEnabledException();
            }

            // simple case: item is not 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 a
                // RemoveFromSelection is valid.
                if (selectionRequired)
                {
                    throw new InvalidOperationException(SR.Get(SRID.SelectionRequired));
                }
            }

            // try to unselect the item
            if (!WindowsListView.UnSelectItem(_hwnd, _item))
            {
                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }
        }
        // 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.Get(SRID.OperationCannotBePerformed));
            }
        }
        // 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));
            }
        }