IEditableCollectionView.Remove(Object) 方法

定義

從集合中移除指定的項目。

C#
public void Remove (object item);

參數

item
Object

要移除的項目。

範例

下列範例會呼叫 CanRemove ,以檢查是否可以從集合中移除專案。 如果可以移除專案,此範例會提示使用者確認動作,並在使用者按兩下[] 時呼叫 Remove 。 如需整個範例,請參閱 使用 IEditableCollectionView 範例變更集合

C#
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);
}

備註

如果 item 不在集合中, Remove 則不會執行任何動作。

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9