IBindingList::AddNew Method

Adds a new item to the list.

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

Object^ AddNew()

Return Value

Type: System::Object
The item added to the list.

ExceptionCondition
NotSupportedException

AllowNew is false.

This method is supported only if AllowNew is true; otherwise, a NotSupportedException is thrown.

Implementing this method means that the IBindingList list must understand the type of objects to add to the list and must understand how to create a new instance of that type. For example, if you have a collection of myCustomer objects, the AddNew method should add a new myCustomer object to the list.

NoteNote

If the objects in this list implement the IEditableObject interface, calling the CancelEdit method should discard an object, not add it to the list, when the object was created using the AddNew method. The object should only be added to the list when the IEditableObject::EndEdit method is called. Therefore, you must sychronize the object and the list carefully.

When this method is called, you should raise a ListChanged event with the ItemAdded enumeration carrying the appropriate index. The added row is in a state where hitting Esc on a DataGridView control can remove the new row. Raising the ListChanged event with the ItemAdded enumeration a second time on this row indicates that the item is now a normal row (not in new state).

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft