AddingNewEventArgs 类

定义

AddingNew 事件提供数据。Provides data for the AddingNew event.

public ref class AddingNewEventArgs : EventArgs
public class AddingNewEventArgs : EventArgs
type AddingNewEventArgs = class
    inherit EventArgs
Public Class AddingNewEventArgs
Inherits EventArgs
继承
AddingNewEventArgs

示例

下面的代码示例演示如何使用 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

注解

AddingNewEventArgs 类为 BindingSource.AddingNew 事件提供数据,该事件指示将某个项添加到集合中。The AddingNewEventArgs class provides data for the BindingSource.AddingNew event, which signals that an item is about to be added to a collection. 事件会在事件处理 AddingNewEventHandler程序中为程序员提供一个选项,通过将 NewObject 属性设置为此新项来提供新的对象。The event gives the programmer, within the event handler AddingNewEventHandler, the option of supplying the new object by setting the NewObject property to this new item. 如果未设置此属性,则集合通常将使用适当类型的无参数构造函数来构造新项。If this property is not set, the collection will typically use the parameterless constructor of the appropriate type to construct a new item. 在任一情况下,新项将添加到集合中。In either case, the new item will be added to the collection.

如果集合还实现 ICancelAddNew 接口,则会暂时添加项,并等待后续提交或回滚。If the collection also implements the ICancelAddNew interface, the item will be provisionally added, waiting a subsequent commit or rollback.

此事件通常用于数据绑定方案,如 System.Windows.Forms.BindingSourceSystem.ComponentModel.BindingList<T>等类中。This event is commonly used in data-binding scenarios, within classes such as System.Windows.Forms.BindingSource and System.ComponentModel.BindingList<T>.

有关如何处理事件的详细信息,请参阅处理和引发事件For more information about how to handle events, see Handling and Raising Events.

构造函数

AddingNewEventArgs()

不使用任何参数初始化 AddingNewEventArgs 类的新实例。Initializes a new instance of the AddingNewEventArgs class using no parameters.

AddingNewEventArgs(Object)

使用指定的对象作为新项初始化 AddingNewEventArgs 类的新实例。Initializes a new instance of the AddingNewEventArgs class using the specified object as the new item.

属性

NewObject

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

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅