RemoveFromSelection Method
Collapse the table of content
Expand the table of content

ISelectionItemProvider.RemoveFromSelection Method ()

 

Removes the current element from the collection of selected items.

Namespace:   System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

void RemoveFromSelection()

Exception Condition

Send an ElementRemovedFromSelectionEvent as appropriate.

System_CAPS_noteNote

This rule does not depend on whether the container allows single or multiple selections, or on what method was used to change the selection. Only the result matters.

The following example code removes the item from a collection of selected items.

/// <summary>
/// Removes the item from the selection in list boxes that support 
/// multiple selection or no selection at all.
/// </summary>
/// <remarks>
/// selectedItems is the collection of selected ListItems.
/// </remarks>
public void RemoveFromSelection()
{
    // Return if the item is already selected.
    if (((ISelectionItemProvider)this).IsSelected)
        return;
    if (((ISelectionProvider)this).IsSelectionRequired & selectedItems.Count <= 0)
        throw new InvalidOperationException("Operation cannot be performed.");

    selectedItems.Remove(this);
    // TODO: Update UI.
}
/// <summary>
/// Specifies whether the item is selected.
/// </summary>
/// <remarks>
/// selectedItems is the collection of selected ListItems.
/// </remarks>
public bool IsSelected
{
    get
    {
        return selectedItems.Contains(this);
    }
}

.NET Framework
Available since 3.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2016 Microsoft