Export (0) Print
Expand All

IEditableCollectionView.CommitNew Method

Updated: July 2008

Ends the add transaction and saves the pending new item.

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

void CommitNew()
You cannot use methods in XAML.

Any filtering, sorting, or grouping that is applied to the CollectionView is applied to the new item when CommitNew is called.

The following example displays a form that prompts the user to add a new item. If the user submits the form, the example calls CommitNew to add the item to the collection. If the user cancels the form, the example calls CancelNew to discard the item. 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.");
    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.

Community Additions

ADD
Show:
© 2014 Microsoft