CanSelectMultiple Property
Collapse the table of content
Expand the table of content

SelectionPattern.SelectionPatternInformation.CanSelectMultiple Property

 

Gets a value that specifies whether the container allows more than one child element to be selected concurrently.

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

public bool CanSelectMultiple { get; }

Property Value

Type: System.Boolean

true if the control supports multiple selection; otherwise false.

This property can be dynamic For example, in rare cases, a control might allow multiple items to be selected on initialization, but subsequently allow only single selections to be made.

In the following example, a SelectionPatterncontrol pattern is obtained from an AutomationElement and subsequently used to retrieve property values.

///--------------------------------------------------------------------
/// <summary>
/// Obtains a SelectionPattern control pattern from an 
/// automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A SelectionPattern object.
/// </returns>
///--------------------------------------------------------------------
private SelectionPattern GetSelectionPattern(
    AutomationElement targetControl)
{
    SelectionPattern selectionPattern = null;

    try
    {
        selectionPattern =
            targetControl.GetCurrentPattern(SelectionPattern.Pattern)
            as SelectionPattern;
    }
    // Object doesn't support the SelectionPattern control pattern
    catch (InvalidOperationException)
    {
        return null;
    }

    return selectionPattern;
}
///--------------------------------------------------------------------
/// <summary>
/// Gets the current property values from target.
/// </summary>
/// <param name="selectionPattern">
/// A SelectionPattern control pattern obtained from 
/// an automation element representing the selection control.
/// </param>
/// <param name="automationProperty">
/// The automation property of interest.
/// </param>
///--------------------------------------------------------------------
private bool GetSelectionObjectProperty(
    SelectionPattern selectionPattern,
    AutomationProperty automationProperty)
{
    if (automationProperty.Id == 
        SelectionPattern.CanSelectMultipleProperty.Id)
    {
        return selectionPattern.Current.CanSelectMultiple;
    }
    if (automationProperty.Id == 
        SelectionPattern.IsSelectionRequiredProperty.Id)
    {
        return selectionPattern.Current.IsSelectionRequired;
    }
    return false;
}

.NET Framework
Available since 3.0
Return to top
Show:
© 2016 Microsoft