System.Windows.Forms Namesp ...


.NET Framework Class Library
CurrencyManager Class

Manages a list of Binding objects.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Syntax

Visual Basic (Declaration)
Public Class CurrencyManager _
    Inherits BindingManagerBase
Visual Basic (Usage)
Dim instance As CurrencyManager
C#
public class CurrencyManager : BindingManagerBase
Visual C++
public ref class CurrencyManager : public BindingManagerBase
JScript
public class CurrencyManager extends BindingManagerBase
Remarks

The CurrencyManager derives from the BindingManagerBase class. Use the BindingContext to return either a CurrencyManager or a PropertyManager. The actual object returned depends on the data source and data member passed to the Item property of the BindingContext. If the data source is an object that can return only a single property (instead of a list of objects), the type will be a PropertyManager. For example, if you specify a TextBox as the data source, a PropertyManager will be returned. If, on the other hand, the data source is an object that implements the IList, IListSource, or IBindingList interface, a CurrencyManager will be returned.

The Current property returns the current item in the underlying list. To change the current item, set the Position property to a new value. The value must be greater than 0 and must be less than the value of the Count property.

If the underlying data source implements the IBindingList interface, and the AllowNew property is set to true, you can use the AddNew method.

Examples

The following code example binds a TextBox control to a column in a DataTable, gets the CurrencyManager for the binding, and sets its position.

Visual Basic
' Place the next line into the Declarations section of the form.
 Private myCurrencyManager As CurrencyManager

 Private Sub BindControl(myTable As DataTable)
    ' Bind a TextBox control to a DataTable column in a DataSet.
    TextBox1.DataBindings.Add("Text", myTable, "CompanyName")
    ' Specify the CurrencyManager for the DataTable.
    myCurrencyManager = CType(me.BindingContext(myTable), CurrencyManager)
    ' Set the initial Position of the control.
    myCurrencyManager.Position = 0
 End Sub

 Private Sub MoveNext(myCurrencyManager As CurrencyManager)
    If myCurrencyManager.Position = myCurrencyManager.Count - 1 Then 
       MessageBox.Show("You're at end of the records")
    Else
       myCurrencyManager.Position += 1
    End If
 End Sub

 Private Sub MoveFirst(myCurrencyManager As CurrencyManager)
    myCurrencyManager.Position = 0
 End Sub

 Private Sub MovePrevious(myCurrencyManager As CurrencyManager)
    If myCurrencyManager.Position = 0 Then
       MessageBox.Show("You're at the beginning of the records.")
    Else
       myCurrencyManager.Position -= 1
    End if
 End Sub

 Private Sub MoveLast(myCurrencyManager As CurrencyManager)
    myCurrencyManager.Position = myCurrencyManager.Count - 1
 End Sub

C#
private CurrencyManager myCurrencyManager;

 private void BindControl(DataTable myTable){
    // Bind a TextBox control to a DataTable column in a DataSet.
    textBox1.DataBindings.Add("Text", myTable, "CompanyName");
    // Specify the CurrencyManager for the DataTable.
    myCurrencyManager = (CurrencyManager)this.BindingContext[myTable];
    // Set the initial Position of the control.
    myCurrencyManager.Position = 0;
 }

 private void MoveNext(CurrencyManager myCurrencyManager){
    if (myCurrencyManager.Position == myCurrencyManager.Count - 1){
       MessageBox.Show("You're at end of the records");
    }
    else{
      myCurrencyManager.Position += 1;
    }
 }

 private void MoveFirst(CurrencyManager myCurrencyManager){
    myCurrencyManager.Position = 0;
 }

 private void MovePrevious(CurrencyManager myCurrencyManager ){
    if(myCurrencyManager.Position == 0) {
       MessageBox.Show("You're at the beginning of the records.");
    }   
    else{
       myCurrencyManager.Position -= 1;
    }
 }

 private void MoveLast(CurrencyManager myCurrencyManager){
    myCurrencyManager.Position = myCurrencyManager.Count - 1;
 }

Visual C++
CurrencyManager^ myCurrencyManager;
void BindControl( DataTable^ myTable )
{

   // Bind a TextBox control to a DataTable column in a DataSet.
   textBox1->DataBindings->Add( "Text", myTable, "CompanyName" );

   // Specify the CurrencyManager for the DataTable.
   this->myCurrencyManager = dynamic_cast<CurrencyManager^>(this->BindingContext[ myTable ]);

   // Set the initial Position of the control.
   this->myCurrencyManager->Position = 0;
}

void MoveNext( CurrencyManager^ myCurrencyManager )
{
   if ( myCurrencyManager->Position == myCurrencyManager->Count - 1 )
   {
      MessageBox::Show( "You're at end of the records" );
   }
   else
   {
      myCurrencyManager->Position += 1;
   }
}

void MoveFirst( CurrencyManager^ myCurrencyManager )
{
   myCurrencyManager->Position = 0;
}

void MovePrevious( CurrencyManager^ myCurrencyManager )
{
   if ( myCurrencyManager->Position == 0 )
   {
      MessageBox::Show( "You're at the beginning of the records." );
   }
   else
   {
      myCurrencyManager->Position -= 1;
   }
}

void MoveLast( CurrencyManager^ myCurrencyManager )
{
   myCurrencyManager->Position = myCurrencyManager->Count - 1;
}

JScript
private var myCurrencyManager : CurrencyManager;

private function BindControl(myTable : DataTable){
   // Bind a TextBox control to a DataTable column in a DataSet.
   textBox1.DataBindings.Add("Text", myTable, "CompanyName");
   // Specify the CurrencyManager for the DataTable.
   myCurrencyManager = CurrencyManager(this.BindingContext[myTable]);
   // Set the initial Position of the control.
   myCurrencyManager.Position = 0;
}

private function MoveNext(myCurrencyManager : CurrencyManager){
   if (myCurrencyManager.Position == myCurrencyManager.Count - 1){
      MessageBox.Show("You're at end of the records");
   }
   else{
     myCurrencyManager.Position += 1;
   }
}

private function MoveFirst(myCurrencyManager : CurrencyManager){
   myCurrencyManager.Position = 0;
}

private function MovePrevious(myCurrencyManager : CurrencyManager){
   if(myCurrencyManager.Position == 0) {
      MessageBox.Show("You're at the beginning of the records.");
   }   
   else{
      myCurrencyManager.Position -= 1;
   }
}

private function MoveLast(myCurrencyManager : CurrencyManager){
   myCurrencyManager.Position = myCurrencyManager.Count - 1;
}

Inheritance Hierarchy

System..::.Object
  System.Windows.Forms..::.BindingManagerBase
    System.Windows.Forms..::.CurrencyManager
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
See Also

Reference

Tags :


Page view tracker