IEditableCollectionView.Remove(Object) Metoda

Definice

Odebere zadanou položku z kolekce.

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

Parametry

item
Object

Položka k odebrání.

Příklady

Následující příklad volá CanRemove ke kontrole, zda lze položku odebrat z kolekce. Pokud lze položku odebrat, zobrazí se v příkladu výzva k potvrzení akce a Remove volání, pokud uživatel klikne na Ano. Celou ukázku najdete v tématu Změna kolekce pomocí ukázky IEditableCollectionView.

IEditableCollectionView editableCollectionView = 
        itemsControl.Items as IEditableCollectionView; 

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

Poznámky

Pokud item v kolekci není, Remove neprovede se nic.

Platí pro