Export (0) Print
Expand All

IBindingList.AddNew Method

Adds a new item to the list.

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

Object AddNew ()
Object AddNew ()
function AddNew () : Object
Not applicable.

Return Value

The item added to the list.

Exception typeCondition

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).

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft