IEditableCollectionView.CanRemove Property

Definition

Gets a value that indicates whether an item can be removed from the collection.

C#
public bool CanRemove { get; }

Property Value

true if an item can be removed from the collection; otherwise, false.

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.

C#
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);
}

Remarks

CanRemove is false if the underlying collection is read-only.

Applies to

Produkt Verzie
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10