ISelectionItemProvider.RemoveFromSelection Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Remove o elemento atual da coleção de itens selecionados.
public:
void RemoveFromSelection();
public void RemoveFromSelection();
abstract member RemoveFromSelection : unit -> unit
Public Sub RemoveFromSelection ()
Exemplos
O seguinte código de exemplo remove o item de uma coleção de itens selecionados.
/// <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
Observações
Envie um ElementRemovedFromSelectionEvent quando apropriado.
Note
Esta regra não depende se o contentor permite seleções únicas ou múltiplas, nem do método utilizado para alterar a seleção. Só o resultado importa.