SelectionItemPattern.Select Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Anula la selección de los elementos seleccionados y, después, selecciona el elemento actual.
public:
void Select();
public void Select ();
member this.Select : unit -> unit
Public Sub Select ()
Ejemplos
En el ejemplo siguiente se muestra cómo seleccionar un elemento en un contenedor especificando el texto del elemento.
///--------------------------------------------------------------------
/// <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.NameProperty,
itemText,
PropertyConditionFlags.IgnoreCase);
AutomationElement firstMatch =
selectionContainer.FindFirst(TreeScope.Children, propertyCondition);
if (firstMatch != null)
{
try
{
SelectionItemPattern selectionItemPattern;
selectionItemPattern =
firstMatch.GetCurrentPattern(
SelectionItemPattern.Pattern) as SelectionItemPattern;
selectionItemPattern.Select();
}
catch (InvalidOperationException)
{
// Unable to select
return;
}
}
}
'''--------------------------------------------------------------------
''' <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
Try
Dim selectionItemPattern As SelectionItemPattern
selectionItemPattern = DirectCast( _
firstMatch.GetCurrentPattern(selectionItemPattern.Pattern), _
SelectionItemPattern)
selectionItemPattern.Select()
Catch
' Unable to select
Return
End Try
End If
End Sub