CurrencyManager.AddNew 方法

定义

在基础列表中添加一个新项。Adds a new item to the underlying list.

public:
 override void AddNew();
public override void AddNew ();
override this.AddNew : unit -> unit
Public Overrides Sub AddNew ()

异常

基础数据源不实现 IBindingList,或数据源引发了一个异常,原因是用户尝试将一行添加到只读的或固定大小的 DataView 中。The underlying data source does not implement IBindingList, or the data source has thrown an exception because the user has attempted to add a row to a read-only or fixed-size DataView.

示例

下面的代码示例使用 AddNew 方法向列表中添加一个新项。The following code example adds a new item to the list with the AddNew method.

void AddListItem()
{
   
   // Get the CurrencyManager for a DataTable.
   CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(this->BindingContext[ DataTable1 ]);
   myCurrencyManager->AddNew();
}

private void AddListItem()
{
   // Get the CurrencyManager for a DataTable.
   CurrencyManager myCurrencyManager = 
   (CurrencyManager)this.BindingContext[DataTable1];
   myCurrencyManager.AddNew();
}
      
Private Sub AddListItem()
    ' Get the CurrencyManager for a DataTable.
    Dim myCurrencyManager As CurrencyManager = _ 
        CType(Me.BindingContext(DataTable1), CurrencyManager)
    myCurrencyManager.AddNew()
End Sub

注解

仅当数据源实现 IBindingList 接口并且数据源允许添加行(AllowNew true)时,才支持此方法。This method is supported only if the data source implements the IBindingList interface and the data source allows adding rows (AllowNew is true).

备注

此属性旨在允许复杂绑定控件(如 DataGrid 控件)向列表中添加新项。This property was designed to allow complex-bound controls, such as the DataGrid control, to add new items to list.

通常,仅当要创建包含 CurrencyManager的自己的控件时,才使用此属性。You typically use this property only if you are creating your own control that incorporates the CurrencyManager. 否则,若要在数据源为 DataView的情况下添加项,请使用 DataView 类的 DataView.AddNew 方法。Otherwise, to add items if the data source is a DataView, use the DataView.AddNew method of the DataView class. 如果数据源为 DataTable,请使用 NewRow 方法并将行添加到 DataRowCollectionIf the data source is a DataTable, use the NewRow method and add the row to the DataRowCollection.

适用于

另请参阅