Redigera

Dela via


ISelectionItemProvider.AddToSelection Method

Definition

Adds the current element to the collection of selected items.

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

Examples

The following example code adds the item to a collection of selected items.

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

Remarks

If the result of a call to AddToSelection is that a single item is selected, then send an ElementSelectedEvent for that element; otherwise send an ElementAddedToSelectionEvent or ElementRemovedFromSelectionEvent as appropriate.

Note

This rule does not depend on whether the container allows single or multiple selections, or on what method was used to change the selection. Only the result matters.

Applies to

See also