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 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

注釈

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

適用対象