BindingList<T>.AddingNew 事件
定义
在将项添加到该列表之前发生。Occurs before an item is added to the list.
public:
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.