CurrencyManager.AddNew CurrencyManager.AddNew CurrencyManager.AddNew CurrencyManager.AddNew Method

定义

在基础列表中添加一个新项。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接口且数据源允许添加AllowNewtrue时, 才支持此方法。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.AddNew使用DataView类的方法。Otherwise, to add items if the data source is a DataView, use the DataView.AddNew method of the DataView class. 如果数据源是DataTable, 则NewRow使用方法并DataRowCollection将行添加到。If the data source is a DataTable, use the NewRow method and add the row to the DataRowCollection.

适用于

另请参阅