System.ComponentModel.IBindingList.AddNew Method

Adds a new item to the list.

Syntax

public object AddNew ()

Returns

The item added to the list.

Remarks

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

Implementing this method means that the System.ComponentModel.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 IBindingList.AddNew method should add a new myCustomer object to the list.

Note:

If the objects in this list implement the System.ComponentModel.IEditableObject interface, calling the IEditableObject.CancelEdit method should discard an object, not add it to the list, when the object was created using the IBindingList.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 IBindingList.ListChanged event with the ListChangedType.ItemAdded enumeration carrying the appropriate index. The added row is in a state where hitting Esc on a System.Windows.Forms.DataGridView control can remove the new row. Raising the IBindingList.ListChanged event with the ListChangedType.ItemAdded enumeration a second time on this row indicates that the item is now a normal row (not in new state).

Requirements

Namespace: System.ComponentModel
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0