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 ;否则根据需要发送 ElementAddedToSelectionEventElementRemovedFromSelectionEvent

注意

此规则不取决于容器是允许单选还是多选,也不取决于用于更改所选内容的方法。 只有结果才重要。

适用于

另请参阅