IEditableCollectionView.Remove(Object) Metod

Definition

Tar bort det angivna objektet från samlingen.

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

Parametrar

item
Object

Objektet som ska tas bort.

Exempel

I följande exempel anropas CanRemove för att kontrollera om ett objekt kan tas bort från samlingen. Om ett objekt kan tas bort uppmanas användaren i exemplet att bekräfta åtgärden och anropar Remove om användaren klickar på Ja. Hela exemplet finns i Changing a Collection by Using IEditableCollectionView Sample.

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

Kommentarer

Om item inte finns i samlingen, Remove gör ingenting.

Gäller för