This documentation is archived and is not being maintained.

IBindingList.AddNew Method

Adds a new item to the list.

[Visual Basic]
Function AddNew() As Object
object AddNew();
Object* AddNew();
function AddNew() : Object;

Return Value

The item added to the list.


Exception Type Condition
NotSupportedException This method is not supported.


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.

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


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

IBindingList Interface | IBindingList Members | System.ComponentModel Namespace