ISelectionItemProvider.AddToSelection 메서드

정의

선택한 항목의 컬렉션에 현재 요소를 추가합니다.

public:
 void AddToSelection();
public void AddToSelection();
abstract member AddToSelection : unit -> unit
Public Sub AddToSelection ()

예제

다음 예제 코드는 선택한 항목의 컬렉션에 항목을 추가합니다.

/// <summary>
/// Adds an item to the selection for list boxes that 
/// support multiple selection.
/// </summary>
/// <remarks>
/// In a single-selection list box, AddToSelection() is 
/// equivalent to Select().
/// selectedItems is the collection of selected ListItems.
/// </remarks>
public void AddToSelection()
{
    // Return if the item is already selected.
    if (((ISelectionItemProvider)this).IsSelected)
        return;
    selectedItems.Add(this);
    // TODO: Update UI.
}
''' <summary>
''' Adds an item to the selection for list boxes that 
''' support multiple selection.
''' </summary>
''' <remarks>
''' In a single-selection list box, AddToSelection() is 
''' equivalent to Select().
''' selectedItems is the collection of selected ListItems.
''' </remarks>
Public Sub AddToSelection() Implements ISelectionItemProvider.AddToSelection
    ' Return if the item is already selected.
    If (CType(Me, ISelectionItemProvider)).IsSelected Then
        Return
    End If
    selectedItems.Add(Me)
    ' TODO: Update UI.
End Sub
/// <summary>
/// Specifies whether the item is selected.
/// </summary>
/// <remarks>
/// selectedItems is the collection of selected ListItems.
/// </remarks>
public bool IsSelected
{
    get
    {
        return selectedItems.Contains(this);
    }
}
''' <summary>
''' Specifies whether the item is selected.
''' </summary>
''' <remarks>
''' selectedItems is the collection of selected ListItems.
''' </remarks>
Public ReadOnly Property IsSelected() As Boolean Implements ISelectionItemProvider.IsSelected
    Get
        Return selectedItems.Contains(Me)
    End Get
End Property

설명

호출 AddToSelection 결과가 단일 항목이 선택된 경우 해당 요소에 대해 보내 ElementSelectedEvent 거나, 그렇지 않으면 해당 항목을 보내거나 ElementRemovedFromSelectionEvent 적절하게 보냅니 ElementAddedToSelectionEvent 다.

메모

이 규칙은 컨테이너에서 단일 또는 여러 선택을 허용하는지 또는 선택 영역을 변경하는 데 사용된 메서드에 따라 달라지지 않습니다. 결과만 중요합니다.

적용 대상

추가 정보