CurrencyManager 类
管理 Binding 对象的列表。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Public Class CurrencyManager
Inherits BindingManagerBase
用法
Dim instance As CurrencyManager
public class CurrencyManager : BindingManagerBase
public ref class CurrencyManager : public BindingManagerBase
public class CurrencyManager extends BindingManagerBase
public class CurrencyManager extends BindingManagerBase
备注
CurrencyManager 从 BindingManagerBase 类派生。使用 BindingContext 返回一个 CurrencyManager 或一个 PropertyManager。返回的实际对象取决于传递给 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.Object
System.Windows.Forms.BindingManagerBase
System.Windows.Forms.CurrencyManager
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
CurrencyManager 成员
System.Windows.Forms 命名空间
BindingsCollection 类
BindingContext 类
Binding 类