ISelectionItemProvider.AddToSelection Metodo

Definizione

Aggiunge l'elemento corrente alla raccolta di elementi selezionati.

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

Esempio

Il codice di esempio seguente aggiunge l'elemento a una raccolta di elementi selezionati.

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

Commenti

Se il risultato di una chiamata a è che viene selezionato un singolo elemento, inviare un oggetto per tale elemento; in caso contrario, inviare un ElementSelectedEvent oggetto ElementAddedToSelectionEvent o ElementRemovedFromSelectionEvent in base alle AddToSelection esigenze.

Nota

Questa regola non dipende dal fatto che il contenitore consenta selezioni singole o multiple o su quale metodo è stato usato per modificare la selezione. Solo il risultato è importante.

Si applica a

Vedi anche