共用方式為


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 該專案的 ,否則 ElementAddedToSelectionEvent 傳送 或 ElementRemovedFromSelectionEvent

注意

此規則不取決於容器是否允許單一或多個選取專案,或用來變更選取範圍的方法。 只有結果很重要。

適用於

另請參閱