Επεξεργασία

Κοινή χρήση μέσω


IEditableCollectionView.Remove(Object) Method

Definition

Removes the specified item from the collection.

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

Parameters

item
Object

The item to remove.

Examples

The following example calls CanRemove to check whether an item can be removed from the collection. If an item can be removed, the example prompts the user to confirm the action and calls Remove if the user clicks Yes. For the entire sample, see Changing a Collection by Using IEditableCollectionView Sample.

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

Remarks

If item is not in the collection, Remove does nothing.

Applies to