BindingList<T>.AddingNew 事件


在将项添加到该列表之前发生。Occurs before an item is added to the list.

 event System::ComponentModel::AddingNewEventHandler ^ AddingNew;
public event System.ComponentModel.AddingNewEventHandler AddingNew;
member this.AddingNew : System.ComponentModel.AddingNewEventHandler 
Public Custom Event AddingNew As AddingNewEventHandler 


下面的代码示例演示如何处理 AddingNew 事件。The following code example demonstrates how to handle the AddingNew event. 有关完整示例,请参阅 BindingList<T> 类概述主题。For the complete example, see the BindingList<T> class overview topic.

// Create a new part from the text in the two text boxes.
void listOfParts_AddingNew(object sender, AddingNewEventArgs e)
    e.NewObject = new Part(textBox1.Text, int.Parse(textBox2.Text));
' Create a new part from the text in the two text boxes.
Private Sub listOfParts_AddingNew(ByVal sender As Object, _
    ByVal e As AddingNewEventArgs) Handles listOfParts.AddingNew
    e.NewObject = New Part(textBox1.Text, Integer.Parse(textBox2.Text))

End Sub


AddingNew 事件发生在将新对象添加到由 Items 属性表示的集合之前。The AddingNew event occurs before a new object is added to the collection represented by the Items property. 调用 AddNew 方法后,但在创建新项并将其添加到内部列表之前,将引发此事件。This event is raised after the AddNew method is called, but before the new item is created and added to the internal list. 通过处理此事件,程序员可以提供自定义项的创建和插入行为,而无需强制从 BindingList<T> 类派生。By handling this event, the programmer can provide custom item creation and insertion behavior without being forced to derive from the BindingList<T> class.

有关提供自定义新项功能的详细信息,请参阅 AddNew 方法。For more information about supplying custom new item functionality, see the AddNew method. 有关如何处理事件的详细信息,请参阅处理和引发事件For more information about how to handle events, see Handling and Raising Events.