CurrencyManager クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


CurrencyManager は、BindingManagerBase クラスから派生します。CurrencyManager または PropertyManager を返すには、BindingContext を使用します。返される実際のオブジェクトは、BindingContext の Item プロパティに渡されたデータ ソースおよびデータ メンバによって異なります。データ ソースが単一のプロパティだけを返すことができるオブジェクトであり、オブジェクトのリストではない場合、オブジェクトの型は PropertyManager になります。たとえば、データ ソースとして TextBox を指定すると、PropertyManager が返されます。一方、データ ソースが、IList、IListSource、または IBindingList の各インターフェイスを実装している場合は、CurrencyManager が返されます。
Current プロパティは、基になるリストにある現在の項目を返します。現在の項目を変更するには、Position プロパティを新しい値に設定します。この値は、0 より大きい値で、Count プロパティの値より小さい値である必要があります。
基になるデータ ソースで IBindingList インターフェイスを実装し、AllowNew プロパティを true に設定すると、AddNew メソッドを使用できます。

TextBox コントロールを DataTable の列にバインドし、このバインディングの CurrencyManager を取得して、その位置を設定するコード例を次に示します。
' 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
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; }
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; }
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; }

System.Windows.Forms.BindingManagerBase
System.Windows.Forms.CurrencyManager


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- CurrencyManager クラスのページへのリンク