SelectionPattern.SelectionPatternInformation.GetSelection Method ()


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

Retrieves all items in the selection container that are selected.

Namespace:   System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public AutomationElement[] GetSelection()

Return Value

Type: System.Windows.Automation.AutomationElement[]

The collection of selected items. The default is an empty array.

In the following example, a collection of AutomationElements representing the selected items in a selection container is obtained.

/// <summary>
/// Gets the currently selected SelectionItem objects from target.
/// </summary>
/// <param name="ae">The current Selection container object.</param>
private AutomationElement[] GetCurrentSelection(
    AutomationElement selectionContainer)
        SelectionPattern selectionPattern =
            SelectionPattern.Pattern) as SelectionPattern;
        return selectionPattern.Current.GetSelection();
    // Container is not enabled
    catch (InvalidOperationException)
        return null;

.NET Framework
Available since 3.0
Return to top