ISelectionItemProvider.AddToSelection Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Adds the current element to the collection of selected items.

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

void AddToSelection()

If the result of a call to AddToSelection is that a single item is selected, then send an ElementSelectedEvent for that element; otherwise send an ElementAddedToSelectionEvent or 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 adds the item to a collection of selected items.

/// <summary>
/// Adds an item to the selection for list boxes that 
/// support multiple selection.
/// </summary>
/// <remarks>
/// In a single-selection list box, AddToSelection() is 
/// equivalent to Select().
/// selectedItems is the collection of selected ListItems.
/// </remarks>
public void AddToSelection()
{
    // Return if the item is already selected.
    if (((ISelectionItemProvider)this).IsSelected)
        return;
    selectedItems.Add(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: