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;

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は何も行いません。

適用対象