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

適用於