CurrencyManager CurrencyManager CurrencyManager CurrencyManager Class

定义

管理 Binding 对象的列表。Manages a list of Binding objects.

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绑定,并设置其位置。The following code example binds a TextBox control to a column in a DataTable, gets the CurrencyManager for the binding, and sets its position.

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类。The CurrencyManager derives from the BindingManagerBase class. 使用BindingContext以返回CurrencyManagerPropertyManagerUse the BindingContext to return either a CurrencyManager or a PropertyManager. 返回的实际对象取决于数据源和数据成员传递给Item[Object]属性的BindingContextThe actual object returned depends on the data source and data member passed to the Item[Object] property of the BindingContext. 如果数据源,可以返回一个属性 (而不是对象的列表) 的对象的类型将是PropertyManagerIf 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. 例如,如果您指定TextBox作为数据源,PropertyManager将返回。For example, if you specify a TextBox as the data source, a PropertyManager will be returned. 如果后,数据源就是实现的对象IListIListSource,或IBindingList接口,CurrencyManager将返回。If, on the other hand, the data source is an object that implements the IList, IListSource, or IBindingList interface, a CurrencyManager will be returned.

Current属性返回当前项的基础列表中。The Current property returns the current item in the underlying list. 若要更改当前项,设置Position属性的新值。To change the current item, set the Position property to a new value. 值必须大于 0 且小于的值必须Count属性。The value must be greater than 0 and must be less than the value of the Count property.

如果基础数据源实现IBindingList接口,并AllowNew属性设置为true,可以使用AddNew方法。If the underlying data source implements the IBindingList interface, and the AllowNew property is set to true, you can use the AddNew method.

字段

finalType finalType finalType finalType

指定列表的数据类型。Specifies the data type of the list.

listposition listposition listposition listposition

指定 CurrencyManager 在列表中的当前位置。Specifies the current position of the CurrencyManager in the list.

onCurrentChangedHandler onCurrentChangedHandler onCurrentChangedHandler onCurrentChangedHandler

CurrentChanged 事件指定事件处理程序。Specifies the event handler for the CurrentChanged event.

(Inherited from BindingManagerBase)
onPositionChangedHandler onPositionChangedHandler onPositionChangedHandler onPositionChangedHandler

PositionChanged 事件指定事件处理程序。Specifies the event handler for the PositionChanged event.

(Inherited from BindingManagerBase)

属性

Bindings Bindings Bindings Bindings

获取所管理绑定的集合。Gets the collection of bindings being managed.

(Inherited from BindingManagerBase)
Count Count Count Count

获取列表中的项数。Gets the number of items in the list.

Current Current Current Current

获取列表中的当前项。Gets the current item in the list.

IsBindingSuspended IsBindingSuspended IsBindingSuspended IsBindingSuspended

获取一个值,该值指示绑定是否已挂起。Gets a value indicating whether binding is suspended.

(Inherited from BindingManagerBase)
List List List List

获得此 CurrencyManager 的列表。Gets the list for this CurrencyManager.

Position Position Position Position

获取或设置在列表中的位置。Gets or sets the position you are at within the list.

方法

AddNew() AddNew() AddNew() AddNew()

在基础列表中添加一个新项。Adds a new item to the underlying list.

CancelCurrentEdit() CancelCurrentEdit() CancelCurrentEdit() CancelCurrentEdit()

取消当前的编辑操作。Cancels the current edit operation.

CheckEmpty() CheckEmpty() CheckEmpty() CheckEmpty()

如果没有列表或列表为空,则会引发异常。Throws an exception if there is no list, or the list is empty.

EndCurrentEdit() EndCurrentEdit() EndCurrentEdit() EndCurrentEdit()

结束当前编辑操作。Ends the current edit operation.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetItemProperties() GetItemProperties() GetItemProperties() GetItemProperties()

获取基础列表的属性说明符集合。Gets the property descriptor collection for the underlying list.

GetItemProperties(ArrayList, ArrayList) GetItemProperties(ArrayList, ArrayList) GetItemProperties(ArrayList, ArrayList) GetItemProperties(ArrayList, ArrayList)

使用指定的 ArrayList 获取绑定的属性说明符集合。Gets the collection of property descriptors for the binding using the specified ArrayList.

(Inherited from BindingManagerBase)
GetItemProperties(Type, Int32, ArrayList, ArrayList) GetItemProperties(Type, Int32, ArrayList, ArrayList) GetItemProperties(Type, Int32, ArrayList, ArrayList) GetItemProperties(Type, Int32, ArrayList, ArrayList)

获取由此 BindingManagerBase 管理的项的属性列表。Gets the list of properties of the items managed by this BindingManagerBase.

(Inherited from BindingManagerBase)
GetListName(ArrayList) GetListName(ArrayList) GetListName(ArrayList) GetListName(ArrayList)

获取特定列表的名称,该列表使用一组指定绑定属性为绑定提供数据。Gets the name of the list supplying the data for the binding using the specified set of bound properties.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnBindingComplete(BindingCompleteEventArgs) OnBindingComplete(BindingCompleteEventArgs) OnBindingComplete(BindingCompleteEventArgs) OnBindingComplete(BindingCompleteEventArgs)

引发 BindingComplete 事件。Raises the BindingComplete event.

(Inherited from BindingManagerBase)
OnCurrentChanged(EventArgs) OnCurrentChanged(EventArgs) OnCurrentChanged(EventArgs) OnCurrentChanged(EventArgs)

引发 CurrentChanged 事件。Raises the CurrentChanged event.

OnCurrentItemChanged(EventArgs) OnCurrentItemChanged(EventArgs) OnCurrentItemChanged(EventArgs) OnCurrentItemChanged(EventArgs)

引发 CurrentItemChanged 事件。Raises the CurrentItemChanged event.

OnDataError(Exception) OnDataError(Exception) OnDataError(Exception) OnDataError(Exception)

引发 DataError 事件。Raises the DataError event.

(Inherited from BindingManagerBase)
OnItemChanged(ItemChangedEventArgs) OnItemChanged(ItemChangedEventArgs) OnItemChanged(ItemChangedEventArgs) OnItemChanged(ItemChangedEventArgs)

引发 ItemChanged 事件。Raises the ItemChanged event.

OnMetaDataChanged(EventArgs) OnMetaDataChanged(EventArgs) OnMetaDataChanged(EventArgs) OnMetaDataChanged(EventArgs)

引发 MetaDataChanged 事件。Raises the MetaDataChanged event.

OnPositionChanged(EventArgs) OnPositionChanged(EventArgs) OnPositionChanged(EventArgs) OnPositionChanged(EventArgs)

引发 PositionChanged 事件。Raises the PositionChanged event.

PullData() PullData() PullData() PullData()

将数据从数据绑定控件拉入到数据源,不返回任何信息。Pulls data from the data-bound control into the data source, returning no information.

(Inherited from BindingManagerBase)
PushData() PushData() PushData() PushData()

将数据从数据源推入到数据绑定控件,不返回任何信息。Pushes data from the data source into the data-bound control, returning no information.

(Inherited from BindingManagerBase)
Refresh() Refresh() Refresh() Refresh()

强制重新填充数据绑定列表。Forces a repopulation of the data-bound list.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

移除指定索引处的项。Removes the item at the specified index.

ResumeBinding() ResumeBinding() ResumeBinding() ResumeBinding()

继续数据绑定。Resumes data binding.

SuspendBinding() SuspendBinding() SuspendBinding() SuspendBinding()

挂起数据绑定,以防止所做的更改对绑定数据源进行更新。Suspends data binding to prevents changes from updating the bound data source.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
UpdateIsBinding() UpdateIsBinding() UpdateIsBinding() UpdateIsBinding()

更新绑定的状态。Updates the status of the binding.

事件

BindingComplete BindingComplete BindingComplete BindingComplete

在数据绑定操作完成时发生。Occurs at the completion of a data-binding operation.

(Inherited from BindingManagerBase)
CurrentChanged CurrentChanged CurrentChanged CurrentChanged

在当前绑定项更改时发生。Occurs when the currently bound item changes.

(Inherited from BindingManagerBase)
CurrentItemChanged CurrentItemChanged CurrentItemChanged CurrentItemChanged

在当前绑定项的状态更改时发生。Occurs when the state of the currently bound item changes.

(Inherited from BindingManagerBase)
DataError DataError DataError DataError

ExceptionBindingManagerBase 处理而未给出任何提示时发生。Occurs when an Exception is silently handled by the BindingManagerBase.

(Inherited from BindingManagerBase)
ItemChanged ItemChanged ItemChanged ItemChanged

在当前项更改后发生。Occurs when the current item has been altered.

ListChanged ListChanged ListChanged ListChanged

当列表更改或列表中的项更改时发生。Occurs when the list changes or an item in the list changes.

MetaDataChanged MetaDataChanged MetaDataChanged MetaDataChanged

List 的元数据更改后发生。Occurs when the metadata of the List has changed.

PositionChanged PositionChanged PositionChanged PositionChanged

Position 属性的值更改后发生。Occurs after the value of the Position property has changed.

(Inherited from BindingManagerBase)

适用于

另请参阅