IEditableCollectionView.Remove(Object) Metódus

Definíció

Eltávolítja a megadott elemet a gyűjteményből.

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

Paraméterek

item
Object

Az eltávolítandó elem.

Példák

Az alábbi példa felhívja CanRemove annak ellenőrzésére, hogy eltávolítható-e egy elem a gyűjteményből. Ha el lehet távolítani egy elemet, a példa arra kéri a felhasználót, hogy erősítse meg a műveletet, és hívja meg Remove , ha a felhasználó az Igen gombra kattint. A teljes minta esetében lásd: Gyűjtemények módosítása az IEditableCollectionView minta használatával.

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

Megjegyzések

Ha item nem szerepel a gyűjteményben, Remove nem tesz semmit.

A következőre érvényes: