ISelectionItemProvider.AddToSelection Método

Definição

Adiciona o elemento atual à coleção de itens selecionados.

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

Exemplos

O código de exemplo a seguir adiciona o item a uma coleção de itens selecionados.

/// <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

Comentários

Se o resultado de uma chamada para AddToSelection for que um único item está selecionado, envie um ElementSelectedEvent para esse elemento; caso contrário, envie um ElementAddedToSelectionEvent ou ElementRemovedFromSelectionEvent conforme apropriado.

Observação

Essa regra não depende se o contêiner permite seleções simples ou múltiplas ou em qual método foi usado para alterar a seleção. Somente o resultado importa.

Aplica-se a

Confira também