SelectionItemPattern.Select Method ()


Deselects any selected items and then selects the current element.

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

Public Sub 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 Sub SelectListItem( _
ByVal selectionContainer As AutomationElement, ByVal itemText As String)
    If selectionContainer Is Nothing OrElse itemText = "" Then
        Throw New ArgumentException("Argument cannot be null or empty.")
    End If

    Dim propertyCondition = _
    New PropertyCondition(AutomationElement.NameProperty, _
    itemText, PropertyConditionFlags.IgnoreCase)

    Dim firstMatch As AutomationElement = _
    selectionContainer.FindFirst(TreeScope.Children, propertyCondition)

    If Not (firstMatch Is Nothing) Then
            Dim selectionItemPattern As SelectionItemPattern
            selectionItemPattern = DirectCast( _
            firstMatch.GetCurrentPattern(selectionItemPattern.Pattern), _
            ' Unable to select
        End Try
    End If
End Sub 'SelectListItem

.NET Framework
Available since 3.0
Return to top