IBindingList.AddNew 方法

定义

将新项添加到列表。Adds a new item to the list.

public:
 System::Object ^ AddNew();
public object AddNew ();
abstract member AddNew : unit -> obj
Public Function AddNew () As Object

返回

添加到列表的项。The item added to the list.

异常

AllowNewfalseAllowNew is false.

注解

仅当AllowNew为时true才支持此方法; 否则, NotSupportedException将引发。This method is supported only if AllowNew is true; otherwise, a NotSupportedException is thrown.

实现此方法意味着IBindingList列表必须了解要添加到列表中的对象的类型, 并且必须了解如何创建该类型的新实例。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. 例如, 如果您有一个myCustomer对象集合, 则该AddNew方法应向列表中添加myCustomer一个新的对象。For example, if you have a collection of myCustomer objects, the AddNew method should add a new myCustomer object to the list.

备注

如果此列表中的对象实现IEditableObject接口, 则在使用CancelEdit AddNew方法创建对象时, 调用方法应丢弃对象, 而不是将其添加到列表。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. 调用IEditableObject.EndEdit方法时, 只应将对象添加到列表。The object should only be added to the list when the IEditableObject.EndEdit method is called. 因此, 你必须仔细同步对象和列表。Therefore, you must synchronize the object and the list carefully.

调用此方法时, 应引发ListChanged ItemAdded包含带有相应索引的枚举的事件。When this method is called, you should raise a ListChanged event with the ItemAdded enumeration carrying the appropriate index. 添加的行处于一种状态, 在该DataGridView状态下, 控件上的命中 Esc 可以删除新行。The added row is in a state where hitting Esc on a DataGridView control can remove the new row. 第二次ItemAdded使用枚举引发事件时,第二次指示该项现在是普通行(不处于新状态)。ListChangedRaising 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).

适用于