IEditableCollectionView.Remove(Object) Methode

Definition

Entfernt das angegebene Element aus der Auflistung.

public:
 void Remove(System::Object ^ item);
public void Remove(object item);
abstract member Remove : obj -> unit
Public Sub Remove (item As Object)

Parameter

item
Object

Das zu entfernende Element.

Beispiele

Im folgenden Beispiel wird überprüft CanRemove , ob ein Element aus der Auflistung entfernt werden kann. Wenn ein Element entfernt werden kann, fordert das Beispiel den Benutzer auf, die Aktion zu bestätigen und aufruft Remove , wenn der Benutzer auf "Ja" klickt. Das gesamte Beispiel finden Sie unter Ändern einer Auflistung mithilfe des IEditableCollectionView-Beispiels.

IEditableCollectionView editableCollectionView =
        itemsControl.Items;

if (!editableCollectionView.CanRemove)
{
    _ = MessageBox.Show("You cannot remove items from the list.");
    return;
}

if (MessageBox.Show("Are you sure you want to remove " + item.Description,
                    "Remove Item", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
    editableCollectionView.Remove(itemsControl.SelectedItem);
}
Dim editableCollectionView As IEditableCollectionView = TryCast(itemsControl.Items, IEditableCollectionView)

If Not editableCollectionView.CanRemove Then
    MessageBox.Show("You cannot remove items from the list.")
    Return
End If

If MessageBox.Show("Are you sure you want to remove " & item.Description, "Remove Item", MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
    editableCollectionView.Remove(itemsControl.SelectedItem)
End If

Hinweise

Wenn item sie nicht in der Sammlung enthalten ist, Remove geschieht nichts.

Gilt für: