다음을 통해 공유


SelectionItemPattern.SelectionItemPatternInformation.IsSelected 속성

정의

항목이 선택되었는지 여부를 나타내는 값을 가져옵니다.

public:
 property bool IsSelected { bool get(); };
public bool IsSelected { get; }
member this.IsSelected : bool
Public ReadOnly Property IsSelected As Boolean

속성 값

Boolean

해당 항목이 선택되면 true이고, 그렇지 않으면 false입니다.

예제

다음 예에서는 현재 선택한 항목의 컬렉션에서 요소를 제거 하는 방법을 보여 줍니다.

///--------------------------------------------------------------------
/// <summary>
/// Retrieves the selection container for a selection item.
/// </summary>
/// <param name="selectionItem">
/// An automation element that supports SelectionItemPattern.
/// </param>
///--------------------------------------------------------------------
private AutomationElement GetSelectionItemContainer(
    AutomationElement selectionItem)
{
    // Selection item cannot be null
    if (selectionItem == null)
    {
        throw new ArgumentException();
    }

    SelectionItemPattern selectionItemPattern = 
        selectionItem.GetCurrentPattern(SelectionItemPattern.Pattern) 
        as SelectionItemPattern;
    if (selectionItemPattern == null)
    {
        return null;
    }
    else
    {
        return selectionItemPattern.Current.SelectionContainer; 
    }
}
'''--------------------------------------------------------------------
''' <summary>
''' Retrieves the selection container for a selection item.
''' </summary>
''' <param name="selectionItem">
''' An automation element that supports SelectionItemPattern.
''' </param>
'''--------------------------------------------------------------------
Private Function GetSelectionItemContainer( _
ByVal selectionItem As AutomationElement) As AutomationElement
    ' Selection item cannot be null
    If selectionItem Is Nothing Then
        Throw New ArgumentException()
    End If

    Dim selectionItemPattern As SelectionItemPattern = _
    DirectCast(selectionItem.GetCurrentPattern( _
    selectionItemPattern.Pattern), SelectionItemPattern)
    If selectionItemPattern Is Nothing Then
        Return Nothing
    Else
        Return selectionItemPattern.Current.SelectionContainer
    End If
End Function 'GetSelectionItemContainer
///--------------------------------------------------------------------
/// <summary>
/// Attempts to remove the current item from a collection 
/// of selected items. 
/// </summary>
/// <param name="selectionItem">
/// An automation element that supports SelectionItemPattern.
/// </param>
///--------------------------------------------------------------------
private void RemoveItemFromSelection(AutomationElement selectionItem)
{
    if (selectionItem == null)
    {
        throw new ArgumentNullException(
            "Argument cannot be null or empty.");
    }

    AutomationElement selectionContainer =
        GetSelectionItemContainer(selectionItem);

    // Selection container cannot be null
    if (selectionContainer == null)
    {
        throw new ElementNotAvailableException();
    }

    SelectionPattern selectionPattern =
        selectionContainer.GetCurrentPattern(SelectionPattern.Pattern)
        as SelectionPattern;

    if (selectionPattern == null)
    {
        return;
    }

    // Check if a selection is required
    if (selectionPattern.Current.IsSelectionRequired && 
        (selectionPattern.Current.GetSelection().GetLength(0) <= 1))
    {
        return;
    }

    SelectionItemPattern selectionItemPattern =
        selectionItem.GetCurrentPattern(
        SelectionItemPattern.Pattern)
        as SelectionItemPattern;
    if ((selectionItemPattern != null) && 
        selectionItemPattern.Current.IsSelected)
    {
        try
        {
            selectionItemPattern.RemoveFromSelection();
        }
        catch (InvalidOperationException)
        {
            // Unable to remove from selection
            return;
        }
    }
}
'''--------------------------------------------------------------------
''' <summary>
''' Attempts to remove the current item from a collection 
''' of selected items. 
''' </summary>
''' <param name="selectionItem">
''' An automation element that supports SelectionItemPattern.
''' </param>
'''--------------------------------------------------------------------
Private Sub RemoveItemFromSelection( _
ByVal selectionItem As AutomationElement)
    If selectionItem Is Nothing Then
        Throw New ArgumentNullException( _
        "Argument cannot be null or empty.")
    End If

    Dim selectionContainer As AutomationElement = _
    GetSelectionItemContainer(selectionItem)

    ' Selection container cannot be null
    If selectionContainer Is Nothing Then
        Throw New ElementNotAvailableException()
    End If

    Dim selectionPattern As SelectionPattern = DirectCast( _
    selectionContainer.GetCurrentPattern(selectionPattern.Pattern), _
    SelectionPattern)

    If selectionPattern Is Nothing Then
        Return
    End If

    ' Check if a selection is required
    If selectionPattern.Current.IsSelectionRequired AndAlso _
    selectionPattern.Current.GetSelection().GetLength(0) <= 1 Then
        Return
    End If

    Dim selectionItemPattern As SelectionItemPattern = DirectCast( _
    selectionItem.GetCurrentPattern(selectionItemPattern.Pattern), _
    SelectionItemPattern)

    If Not (selectionItemPattern Is Nothing) AndAlso selectionItemPattern.Current.IsSelected Then
        Try
            selectionItemPattern.RemoveFromSelection()
        Catch
            ' Unable to remove from selection
            Return
        End Try
    End If
End Sub

적용 대상