CurrencyManager 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
管理 Binding 对象的列表。
public ref class CurrencyManager : System::Windows::Forms::BindingManagerBase
public class CurrencyManager : System.Windows.Forms.BindingManagerBase
type CurrencyManager = class
inherit BindingManagerBase
Public Class CurrencyManager
Inherits BindingManagerBase
- 继承
示例
下面的代码示例将 TextBox 控件绑定到 中的 DataTable列,获取 CurrencyManager 绑定的 ,并设置其位置。
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 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;
}
' 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
注解
CurrencyManager派生自 BindingManagerBase 类。 BindingContext使用 返回 CurrencyManager 或 PropertyManager。 返回的实际对象取决于传递给 Item[] 的 属性的 BindingContext数据源和数据成员。 如果数据源是一个对象,该对象只能返回单个属性 (而不是) 对象列表,则类型将为 PropertyManager。 例如,如果指定 TextBox 作为数据源, PropertyManager 则将返回 。 另一方面,如果数据源是实现 IList、 IListSource或 IBindingList 接口的对象, CurrencyManager 则将返回 。
属性 Current 返回基础列表中的当前项。 若要更改当前项,请将 Position 属性设置为新值。 该值必须大于 0,并且必须小于 属性的值 Count 。
如果基础数据源实现 IBindingList 接口,并且 属性 AllowNew 设置为 true
,则可以使用 AddNew 方法。
字段
finalType |
指定列表的数据类型。 |
listposition |
指定 CurrencyManager 在列表中的当前位置。 |
onCurrentChangedHandler |
为 CurrentChanged 事件指定事件处理程序。 (继承自 BindingManagerBase) |
onPositionChangedHandler |
为 PositionChanged 事件指定事件处理程序。 (继承自 BindingManagerBase) |
属性
Bindings |
获取所管理绑定的集合。 (继承自 BindingManagerBase) |
Count |
获取列表中的项数。 |
Current |
获取列表中的当前项。 |
IsBindingSuspended |
获取一个值,该值指示绑定是否已挂起。 (继承自 BindingManagerBase) |
List |
获得此 CurrencyManager 的列表。 |
Position |
获取或设置在列表中的位置。 |
方法
事件
BindingComplete |
在数据绑定操作完成时发生。 (继承自 BindingManagerBase) |
CurrentChanged |
在当前绑定项更改时发生。 (继承自 BindingManagerBase) |
CurrentItemChanged |
在当前绑定项的状态更改时发生。 (继承自 BindingManagerBase) |
DataError |
当 Exception 被 BindingManagerBase 处理而未给出任何提示时发生。 (继承自 BindingManagerBase) |
ItemChanged |
在当前项更改后发生。 |
ListChanged |
当列表或列表中的项更改时发生。 |
MetaDataChanged |
在 List 的元数据更改后发生。 |
PositionChanged |
在 Position 属性的值更改后发生。 (继承自 BindingManagerBase) |