IEditableCollectionView.Remove(Object) メソッド

定義

指定した項目をコレクションから削除します。

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

パラメーター

item
Object

削除する項目。

次の例では、 を呼び出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

注釈

がコレクション内にない場合 item は、 Remove 何も行われません。

適用対象