This documentation is archived and is not being maintained.

CurrencyManager.AddNew Method

Adds a new item to the underlying list.

[Visual Basic]
Overrides Public Sub AddNew()
[C#]
public override void AddNew();
[C++]
public: void AddNew();
[JScript]
public override function AddNew();

Exceptions

Exception Type Condition
NotSupportedException 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 DataView.

Remarks

This method is only supported if the data source implements IBindingList and the data source allows adding rows.

Note   This property was designed to allow complex-bound controls, such as the DataGrid control, to add new items to list.

You typically use this property only if you are creating your own control incorporating the CurrencyManager. Otherwise, to add items, if the data source is a DataView, use the AddNew method of the DataView class. If the data source is a DataTable, use the NewRow method and add the row to the DataRowCollection.

Example

The following example adds a new item to the list with the AddNew method.

[Visual Basic] 
Private Sub AddListItem()
    ' Get the CurrencyManager for a DataTable.
    Dim myCurrencyManager As CurrencyManager = _ 
        CType(Me.BindingContext(DataTable1), CurrencyManager)
    myCurrencyManager.AddNew()
End Sub 'AddListItem

[C#] 
private void AddListItem()
{
   // Get the CurrencyManager for a DataTable.
   CurrencyManager myCurrencyManager = 
   (CurrencyManager)this.BindingContext[DataTable1];
   myCurrencyManager.AddNew();
}
      

[C++] 
private:
void AddListItem()
{
   // Get the CurrencyManager for a DataTable.
   CurrencyManager* myCurrencyManager = 
   dynamic_cast<CurrencyManager*>(this->BindingContext->Item[DataTable1]);
   myCurrencyManager->AddNew();
}
      

[JScript] 
private function AddListItem()
{
   // Get the CurrencyManager for a DataTable.
   var myCurrencyManager : CurrencyManager = 
   CurrencyManager(this.BindingContext[DataTable1]);
   myCurrencyManager.AddNew();
}
      

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

CurrencyManager Class | CurrencyManager Members | System.Windows.Forms Namespace

Show: