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 ()
public void Select ()
public function Select ()
Not applicable.

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

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