IEditableCollectionView.CanRemove プロパティ

定義

項目をコレクションから削除できるかどうかを示す値を取得します。

public:
 property bool CanRemove { bool get(); };
public bool CanRemove { get; }
member this.CanRemove : bool
Public ReadOnly Property CanRemove As Boolean

プロパティ値

true 項目をコレクションから削除できる場合。それ以外の場合は false

次の例では、 CanRemove を呼び出して、コレクションから項目を削除できるかどうかを確認します。 項目を削除できる場合は、アクションの確認をユーザーに求め、ユーザーが [はい] をクリックするとRemoveを呼び出します。 サンプル全体については、「 IEditableCollectionView サンプルを使用したコレクションの変更」を参照してください。

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

注釈

CanRemove は、基になるコレクションが読み取り専用の場合に false されます。

適用対象