This documentation is archived and is not being maintained.

IEditableCollectionView Interface

Defines methods and properties that a CollectionView implements to provide editing capabilities to a collection.

Namespace:  System.ComponentModel
Assembly:  WindowsBase (in WindowsBase.dll)

public interface IEditableCollectionView

The IEditableCollectionView type exposes the following members.

Public propertyCanAddNewGets a value that indicates whether a new item can be added to the collection.
Public propertyCanCancelEditGets a value that indicates whether the collection view can discard pending changes and restore the original values of an edited object.
Public propertyCanRemoveGets a value that indicates whether an item can be removed from the collection.
Public propertyCurrentAddItemGets the item that is being added during the current add transaction.
Public propertyCurrentEditItemGets the item in the collection that is being edited.
Public propertyIsAddingNewGets a value that indicates whether an add transaction is in progress.
Public propertyIsEditingItemGets a value that indicates whether an edit transaction is in progress.
Public propertyNewItemPlaceholderPositionGets or sets the position of the new item placeholder in the collection view.

Public methodAddNewAdds a new item to the collection.
Public methodCancelEditEnds the edit transaction and, if possible, restores the original value to the item.
Public methodCancelNewEnds the add transaction and discards the pending new item.
Public methodCommitEditEnds the edit transaction and saves the pending changes.
Public methodCommitNewEnds the add transaction and saves the pending new item.
Public methodEditItemBegins an edit transaction of the specified item.
Public methodRemoveRemoves the specified item from the collection.
Public methodRemoveAtRemoves the item at the specified position from the collection.

When a collection view implements the IEditableCollectionView interface, you can directly change the underlying collection, if it allows changes to be made, by using the methods and properties that IEditableCollectionView exposes, regardless of the collection's type.

The types ItemCollection, BindingListCollectionView, and ListCollectionView are the types that ship with Windows Presentation Foundation (WPF) that inherit from CollectionView. These types also implement the IEditableCollectionView, so you can edit a collection that uses one of those types. ItemCollection, in particular, is often used because the ItemsControl.Items property is an ItemCollection.

The following example shows how to add an item to a collection by using methods that are defined by IEditableCollectionView. This application displays a list of items for sale and gives the user the option of adding, editing, or removing an item. When the user adds or edits an item, a form prompts the user to enter a new item. If the user submits the form, the item is committed to the collection. If the user cancels the form, the item is discarded. For the entire sample, see Changing a Collection by Using IEditableCollectionView Sample.

            IEditableCollectionView editableCollectionView = 
                itemsControl.Items as IEditableCollectionView; 

            if (!editableCollectionView.CanAddNew)
                MessageBox.Show("You cannot add items to the list.");

            // Create a window that prompts the user to enter a new
            // item to sell.
            ChangeItemWindow win = new ChangeItemWindow();

            //Create a new item to be added to the collection.
            win.DataContext = editableCollectionView.AddNew();

            // If the user submits the new item, commit the new
            // object to the collection.  If the user cancels 
            // adding the new item, discard the new item.
            if ((bool)win.ShowDialog())

.NET Framework

Supported in: 4, 3.5 SP1, 3.0 SP2

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.