CurrencyManager Class

Definition

管理 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
Inheritance
CurrencyManager

Examples

下面的代码示例将 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

Remarks

CurrencyManager 派生自 BindingManagerBase 类。The CurrencyManager derives from the BindingManagerBase class. 使用 BindingContext 返回 CurrencyManagerPropertyManagerUse the BindingContext to return either a CurrencyManager or a PropertyManager. 返回的实际对象取决于传递到 BindingContextItem[] 属性的数据源和数据成员。The actual object returned depends on the data source and data member passed to the Item[] 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 作为数据源,则将返回一个 PropertyManagerFor example, if you specify a TextBox as the data source, a PropertyManager will be returned. 另一方面,如果数据源是实现 IListIListSourceIBindingList 接口的对象,则将返回 CurrencyManagerIf, 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.

Fields

finalType

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

listposition

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

onCurrentChangedHandler

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

(Inherited from BindingManagerBase)
onPositionChangedHandler

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

(Inherited from BindingManagerBase)

Properties

Bindings

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

(Inherited from BindingManagerBase)
Count

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

Current

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

IsBindingSuspended

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

(Inherited from BindingManagerBase)
List

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

Position

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

Methods

AddNew()

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

CancelCurrentEdit()

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

CheckEmpty()

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

EndCurrentEdit()

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

Equals(Object)

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

(Inherited from Object)
GetHashCode()

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

(Inherited from Object)
GetItemProperties()

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

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)

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

(Inherited from BindingManagerBase)
GetListName(ArrayList)

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

GetType()

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

(Inherited from Object)
MemberwiseClone()

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

(Inherited from Object)
OnBindingComplete(BindingCompleteEventArgs)

引发 BindingComplete 事件。Raises the BindingComplete event.

(Inherited from BindingManagerBase)
OnCurrentChanged(EventArgs)

引发 CurrentChanged 事件。Raises the CurrentChanged event.

OnCurrentItemChanged(EventArgs)

引发 CurrentItemChanged 事件。Raises the CurrentItemChanged event.

OnCurrentItemChanged(EventArgs)

引发 CurrentItemChanged 事件。Raises the CurrentItemChanged event.

(Inherited from BindingManagerBase)
OnDataError(Exception)

引发 DataError 事件。Raises the DataError event.

(Inherited from BindingManagerBase)
OnItemChanged(ItemChangedEventArgs)

引发 ItemChanged 事件。Raises the ItemChanged event.

OnMetaDataChanged(EventArgs)

引发 MetaDataChanged 事件。Raises the MetaDataChanged event.

OnPositionChanged(EventArgs)

引发 PositionChanged 事件。Raises the PositionChanged event.

PullData()

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

(Inherited from BindingManagerBase)
PushData()

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

(Inherited from BindingManagerBase)
Refresh()

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

RemoveAt(Int32)

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

ResumeBinding()

继续数据绑定。Resumes data binding.

SuspendBinding()

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

ToString()

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

(Inherited from Object)
UpdateIsBinding()

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

Events

BindingComplete

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

(Inherited from BindingManagerBase)
CurrentChanged

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

(Inherited from BindingManagerBase)
CurrentItemChanged

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

(Inherited from BindingManagerBase)
DataError

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

(Inherited from BindingManagerBase)
ItemChanged

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

ListChanged

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

MetaDataChanged

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

PositionChanged

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

(Inherited from BindingManagerBase)

Applies to

See also