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 則不會執行任何動作。

適用於