This documentation is archived and is not being maintained.

SelectionItemPattern.Select Method

Deselects any selected items and then selects the current element.

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

public void Select()

The following example shows how to select an item in a container by specifying the text of the item.

/// <summary>
/// Selects a string item in a container.
/// </summary>
/// <param name="selectionContainer">The selection container.</param>
/// <param name="itemText">The text to select.</param>
/// <remarks>
/// This deselects any currently selected items. 
/// To add the item to the current selection in a multiselect list, 
/// use AddToSelection instead of Select.
/// </remarks>
public void SelectListItem(
    AutomationElement selectionContainer, String itemText)
    if ((selectionContainer == null) || (itemText == ""))
        throw new ArgumentException(
            "Argument cannot be null or empty.");

    Condition propertyCondition = new PropertyCondition(

    AutomationElement firstMatch = 
        selectionContainer.FindFirst(TreeScope.Children, propertyCondition);

    if (firstMatch != null)
            SelectionItemPattern selectionItemPattern;
            selectionItemPattern = 
            SelectionItemPattern.Pattern) as SelectionItemPattern;
        catch (InvalidOperationException)
            // Unable to select

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.