Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ISelectionItemProvider.AddToSelection Method

Adds the current element to the collection of selected items.

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

void AddToSelection ()
void AddToSelection ()
function AddToSelection ()
Not applicable.
Exception typeCondition

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.

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);
        }
    }

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.