IEditableCollectionView.CanRemove Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a value that indicates whether an item can be removed from the collection.
public:
property bool CanRemove { bool get(); };
public bool CanRemove { get; }
member this.CanRemove : bool
Public ReadOnly Property CanRemove As Boolean
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.
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
CanRemove is false
if the underlying collection is read-only.
Applies to
Зворотний зв’язок
https://aka.ms/ContentUserFeedback.
Очікується незабаром: протягом 2024 року ми будемо припиняти використання механізму реєстрації проблем у GitHub для зворотного зв’язку щодо вмісту й замінювати його новою системою зворотного зв’язку. Докладніше:Надіслати й переглянути відгук про