AddingNewEventArgs.NewObject 属性


获取或设置要添加到绑定列表的对象。Gets or sets the object to be added to the binding list.

 property System::Object ^ NewObject { System::Object ^ get(); void set(System::Object ^ value); };
public object NewObject { get; set; }
member this.NewObject : obj with get, set
Public Property NewObject As Object


要作为新项添加到关联的集合中的 ObjectThe Object to be added as a new item to the associated collection.


下面的代码示例演示如何使用 AddingNewEventArgs 类处理 BindingSource.AddingNew 事件。The following code example demonstrates how to use the AddingNewEventArgs class to handle the BindingSource.AddingNew event. 此代码示例摘自如何:自定义项添加到 Windows 窗体 BindingSource中提供的一个更大的示例。This code example is part of a larger example provided in How to: Customize Item Addition with the Windows Forms BindingSource.

// This event handler provides custom item-creation behavior.
void OnCustomersBindingSourceAddingNew(Object^ sender, 
    AddingNewEventArgs^ e)
    e->NewObject = DemoCustomer::CreateNewCustomer();
// This event handler provides custom item-creation behavior.
void customersBindingSource_AddingNew(
    object sender, 
    AddingNewEventArgs e)
    e.NewObject = DemoCustomer.CreateNewCustomer();
' This event handler provides custom item-creation behavior.
 Private Sub customersBindingSource_AddingNew( _
 ByVal sender As Object, _
 ByVal e As AddingNewEventArgs) _
 Handles customersBindingSource.AddingNew

     e.NewObject = DemoCustomer.CreateNewCustomer()

 End Sub


如果将 NewObject 属性设置为 null,则指示集合将采用标准操作,这通常需要使用其无参数构造函数创建适当类型的对象,然后将其添加到集合中。If the NewObject property is set to null, it indicates that the collection is to take the standard action, which typically entails creating an object of the appropriate type using its parameterless constructor, and then adding it to the collection.