ISelectionItemProvider.RemoveFromSelection 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从所选项的集合删除当前元素。
public:
void RemoveFromSelection();
public void RemoveFromSelection ();
abstract member RemoveFromSelection : unit -> unit
Public Sub RemoveFromSelection ()
示例
以下示例代码从选定项的集合中删除该项。
/// <summary>
/// Removes the item from the selection in list boxes that support
/// multiple selection or no selection at all.
/// </summary>
/// <remarks>
/// selectedItems is the collection of selected ListItems.
/// </remarks>
public void RemoveFromSelection()
{
// Return if the item is already selected.
if (((ISelectionItemProvider)this).IsSelected)
return;
if (((ISelectionProvider)this).IsSelectionRequired & selectedItems.Count <= 0)
throw new InvalidOperationException("Operation cannot be performed.");
selectedItems.Remove(this);
// TODO: Update UI.
}
''' <summary>
''' Removes the item from the selection in list boxes that support
''' multiple selection or no selection at all.
''' </summary>
''' <remarks>
''' selectedItems is the collection of selected ListItems.
''' </remarks>
Public Sub RemoveFromSelection() Implements ISelectionItemProvider.RemoveFromSelection
' Return if the item is already selected.
If (CType(Me, ISelectionItemProvider)).IsSelected Then
Return
End If
If (CType(Me, ISelectionProvider)).IsSelectionRequired And selectedItems.Count <= 0 Then
Throw New InvalidOperationException("Operation cannot be performed.")
End If
selectedItems.Remove(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
注解
ElementRemovedFromSelectionEvent根据需要发送 。
注意
此规则不取决于容器是允许单选还是多选,也不取决于用于更改所选内容的方法。 只有结果才重要。