SelectionItemPattern.AddToSelection 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
선택한 항목 컬렉션에 현재 요소를 추가합니다.
public:
void AddToSelection();
public void AddToSelection ();
member this.AddToSelection : unit -> unit
Public Sub AddToSelection ()
예외
CanSelectMultipleProperty
=
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 add the current item to a collection
/// of selected items.
/// </summary>
/// <param name="selectionItem">
/// An automation element that supports SelectionItemPattern.
/// </param>
///--------------------------------------------------------------------
private void AddItemToSelection(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;
}
if (selectionPattern.Current.CanSelectMultiple)
{
SelectionItemPattern selectionItemPattern =
selectionItem.GetCurrentPattern(
SelectionItemPattern.Pattern)
as SelectionItemPattern;
if (selectionItemPattern != null)
{
try
{
selectionItemPattern.AddToSelection();
}
catch (InvalidOperationException)
{
// Unable to add to selection
return;
}
}
}
}
'''--------------------------------------------------------------------
''' <summary>
''' Attempts to add the current item to a collection
''' of selected items.
''' </summary>
''' <param name="selectionItem">
''' An automation element that supports SelectionItemPattern.
''' </param>
'''--------------------------------------------------------------------
Private Sub AddItemToSelection(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
If selectionPattern.Current.CanSelectMultiple Then
Dim selectionItemPattern As SelectionItemPattern = DirectCast( _
selectionItem.GetCurrentPattern(selectionItemPattern.Pattern), _
SelectionItemPattern)
If Not (selectionItemPattern Is Nothing) Then
Try
selectionItemPattern.AddToSelection()
Catch
' Unable to add to selection
Return
End Try
End If
End If
End Sub
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET