Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
IEditableCollectionView Interface

Updated: July 2008

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

Namespace:  System.ComponentModel
Assembly:  WindowsBase (in WindowsBase.dll)
Visual Basic (Declaration)
Public Interface IEditableCollectionView
Visual Basic (Usage)
Dim instance As IEditableCollectionView
C#
public interface IEditableCollectionView
Visual C++
public interface class IEditableCollectionView
JScript
public interface IEditableCollectionView
XAML
Interfaces cannot be used directly in XAML; see types that implement this interface.

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.

C#
IEditableCollectionView editableCollectionView = 
    itemsControl.Items as IEditableCollectionView; 

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

// 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())
{
    editableCollectionView.CommitNew();
}
else
{
    editableCollectionView.CancelNew();
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1, 3.0 SP2

Date

History

Reason

July 2008

Added topic for new interface.

SP1 feature change.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
tip: see IEditableObject      SAAB9-3   |   Edit   |   Show History
http://blogs.msdn.com/vinsibal/archive/2008/05/20/wpf-3-5-sp1-feature-ieditablecollectionview.aspx?CommentPosted=true#commentmessage

IEditableObject is key. I still have no idea how to gain better control of AddNew() and CommitNew() though. :(
Tags What's this?: Add a tag
Flag as ContentBug
tip: see IEditableObject      SAAB9-3   |   Edit   |   Show History
http://blogs.msdn.com/vinsibal/archive/2008/05/20/wpf-3-5-sp1-feature-ieditablecollectionview.aspx?CommentPosted=true#commentmessage

IEditableObject is key. I still have no idea how to gain better control of AddNew() and CommitNew() though. :(
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker