BindingManagerBase BindingManagerBase BindingManagerBase BindingManagerBase Class

定义

管理绑定到相同数据源和数据成员的所有 Binding 对象。Manages all Binding objects that are bound to the same data source and data member. 此类为抽象类。This class is abstract.

public ref class BindingManagerBase abstract
public abstract class BindingManagerBase
type BindingManagerBase = class
Public MustInherit Class BindingManagerBase
继承
BindingManagerBaseBindingManagerBaseBindingManagerBaseBindingManagerBase
派生

示例

下面的代码示例使用BindingContext以返回BindingManagerBase特定数据源。The following code example uses the BindingContext to return a BindingManagerBase for a specific data source. (该示例假定已声明myBindingManagerBase模块的声明部分中。)然后,该示例添加到的事件委托CurrentChangedPositionChanged事件。(The example assumes you have declared myBindingManagerBase in the Declarations section of the module.) The example then adds event delegates to the CurrentChanged and PositionChanged events. 最后,该示例包含四个方法 (MoveNextMovePreviousMoveFirst,和MoveLast) 的递增或递减Position属性,并设置Position到列表中的第一个或最后一个行。Lastly, the example contains four methods (MoveNext, MovePrevious, MoveFirst, and MoveLast) that increment or decrement the Position property, and set the Position to the first or last row in the list. 在列表中的最后一行确定使用Count属性。The last row in the list is determined by using the Count property.

void GetBindingManagerBase()
{
   
   /* CustomersToOrders is the RelationName of a DataRelation. 
      Therefore, the list maintained by the BindingManagerBase is the
      list of orders that belong to a specific customer in the 
      DataTable named Customers, found in DataSet1. */
   myBindingManagerBase = this->BindingContext[DataSet1, "Customers.CustomersToOrders"];
   
   // Adds delegates to the CurrentChanged and PositionChanged events.
   myBindingManagerBase->PositionChanged += gcnew EventHandler( this, &Form1::BindingManagerBase_PositionChanged );
   myBindingManagerBase->CurrentChanged += gcnew EventHandler( this, &Form1::BindingManagerBase_CurrentChanged );
}

void BindingManagerBase_PositionChanged( Object^ sender, EventArgs^ /*e*/ )
{
   
   // Prints the new Position of the BindingManagerBase.
   Console::Write( "Position Changed: " );
   Console::WriteLine( (dynamic_cast<BindingManagerBase^>(sender))->Position );
}

void BindingManagerBase_CurrentChanged( Object^ sender, EventArgs^ /*e*/ )
{
   
   // Prints the new value of the current object.
   Console::Write( "Current Changed: " );
   Console::WriteLine( (dynamic_cast<BindingManagerBase^>(sender))->Current );
}

void MoveNext()
{
   
   // Increments the Position property value by one.
   myBindingManagerBase->Position = myBindingManagerBase->Position + 1;
}

void MovePrevious()
{
   
   // Decrements the Position property value by one.
   myBindingManagerBase->Position = myBindingManagerBase->Position - 1;
}

void MoveFirst()
{
   
   // Goes to the first row in the list.
   myBindingManagerBase->Position = 0;
}

void MoveLast()
{
   
   // Goes to the last row in the list.
   myBindingManagerBase->Position = myBindingManagerBase->Count - 1;
}

private void GetBindingManagerBase()
{
   /* CustomersToOrders is the RelationName of a DataRelation. 
   Therefore, the list maintained by the BindingManagerBase is the
   list of orders that belong to a specific customer in the 
   DataTable named Customers, found in DataSet1. */
   myBindingManagerBase = 
   this.BindingContext[DataSet1, "Customers.CustomersToOrders"];

   // Adds delegates to the CurrentChanged and PositionChanged events.
   myBindingManagerBase.PositionChanged += 
   new EventHandler(BindingManagerBase_PositionChanged);
   myBindingManagerBase.CurrentChanged +=
   new EventHandler(BindingManagerBase_CurrentChanged);
}

private void BindingManagerBase_PositionChanged
(object sender, EventArgs e)
{
   // Prints the new Position of the BindingManagerBase.
   Console.Write("Position Changed: ");
   Console.WriteLine(((BindingManagerBase)sender).Position);
}

private void BindingManagerBase_CurrentChanged
(object sender, EventArgs e)
{
   // Prints the new value of the current object.
   Console.Write("Current Changed: ");
   Console.WriteLine(((BindingManagerBase)sender).Current);
}

private void MoveNext()
{
   // Increments the Position property value by one.
   myBindingManagerBase.Position += 1;
}

private void MovePrevious()
{
   // Decrements the Position property value by one.
   myBindingManagerBase.Position -= 1;
}

private void MoveFirst()
{
   // Goes to the first row in the list.
   myBindingManagerBase.Position = 0;
}

private void MoveLast()
{
   // Goes to the last row in the list.
   myBindingManagerBase.Position = 
   myBindingManagerBase.Count - 1;
}

Private Sub GetBindingManagerBase
   ' CustomersToOrders is the RelationName of a DataRelation.
   ' Therefore, the list maintained by the BindingManagerBase is the
   ' list of orders that belong to a specific customer in the
   ' DataTable named Customers, found in DataSet.
   myBindingManagerBase = Me.BindingContext(DataSet1, _
   "Customers.CustomersToOrders")

   ' Adds delegates to the CurrentChanged and PositionChanged events.
   AddHandler myBindingManagerBase.PositionChanged, _
   AddressOf BindingManagerBase_PositionChanged
   AddHandler myBindingManagerBase.CurrentChanged, _
   AddressOf BindingManagerBase_CurrentChanged
End Sub

Private Sub BindingManagerBase_PositionChanged _
(sender As Object, e As EventArgs)

   ' Prints the new Position of the BindingManagerBase.
   Console.Write("Position Changed: ")
   Console.WriteLine(CType(sender, BindingManagerBase).Position)
End Sub

Private Sub BindingManagerBase_CurrentChanged _
(sender As Object, e As EventArgs)

   ' Prints the new value of the current object.
   Console.Write("Current Changed: ")
   Console.WriteLine(CType(sender, BindingManagerBase).Current)
End Sub

Private Sub MoveNext
   ' Increments the Position property value by one.
   myBindingManagerBase.Position += 1
End Sub

Private Sub MovePrevious
   ' Decrements the Position property value by one.
   myBindingManagerBase.Position -= 1
End Sub

Private Sub MoveFirst
   ' Goes to the first row in the list.
   myBindingManagerBase.Position = 0
End Sub

Private Sub MoveLast
   ' Goes to the last row in the list.
   myBindingManagerBase.Position = _
   myBindingManagerBase.Count - 1
End Sub

注解

BindingManagerBase允许 Windows 窗体上的数据绑定控件绑定到相同的数据源的同步。The BindingManagerBase enables the synchronization of data-bound controls on a Windows Form that are bound to the same data source. (有关将控件绑定到数据源的简单的详细信息,请参阅Binding类。)例如,假设一个窗体包含两个TextBox到同一数据源但不同的列绑定的控件。(For more information about simple binding a control to a data source, see the Binding class.) For example, suppose that a form contains two TextBox controls that are bound to the same data source but to different columns. 数据源可以是DataTable,包含客户名称的列可能包含第一个和最后一个名称。The data source might be a DataTable that contains customer names, while the columns might contain the first and last names. 两个控件必须同步以便显示同一个客户一起使用以获得正确的第一个和最后一个名称。The two controls must be synchronized in order to display the correct first and last names together for the same customer. CurrencyManager,后者又继承BindingManagerBase类中,通过维护到数据源中的当前项指针来实现此同步。The CurrencyManager, which inherits from the BindingManagerBase class, accomplishes this synchronization by maintaining a pointer to the current item in the data source. TextBox控件将绑定到当前项,以便它们显示在同一行的信息。The TextBox controls are bound to the current item so they display the information for the same row. 当前项更改时,CurrencyManager通知所有绑定控件,以便它们可以刷新其数据。When the current item changes, the CurrencyManager notifies all the bound controls so that they can refresh their data. 此外,可以设置Position属性以指定在行DataTable控件所指向的。Furthermore, you can set the Position property to specify the row in the DataTable that the controls point to. 若要确定数据源中有多少行,请使用Count属性。To determine how many rows exist in the data source, use the Count property.

CurrencyManager是必需的因为数据源不一定是维护当前项指针。The CurrencyManager is necessary because data sources do not necessarily maintain a current-item pointer. 例如,数组和ArrayList对象可以是数据源,但它们不具有返回当前项的属性。For instance, arrays and ArrayList objects can be data sources, but they do not have a property that returns the current item. 若要获取当前项,请使用Current属性。To get the current item, use the Current property.

PropertyManager也继承BindingManagerBase,并使用它来维护当前属性的对象,而不是数据源中的当前对象的属性。The PropertyManager also inherits from the BindingManagerBase, and it is used to maintain the current property of an object, rather than the property of a current object in a data source. 出于此原因,尝试设置PositionCount属性PropertyManager不起作用。For this reason, trying to set the Position or Count property for a PropertyManager has no effect.

若要创建BindingManagerBase,使用BindingContext类,该类返回CurrencyManagerPropertyManager,取决于所管理的数据源。To create a BindingManagerBase, use the BindingContext class, which returns either a CurrencyManager or a PropertyManager, depending on the data source being managed.

解决方案编程人员将控件直接绑定到我们鼓励BindingSource组件,它将作为数据源和连接到实际目标数据源的数据连接器。Solutions programmers are encouraged to bind controls directly to a BindingSource component, which acts as both a data source and data connector to the actual target data source. BindingSource 极大地简化了这两个简单和复杂数据绑定,其中包括管理控件和其目标之间的货币。BindingSource greatly simplifies both simple and complex data binding, including managing currency between the control and its target.

继承者说明

继承自BindingManagerBase,必须重写以下抽象成员: AddNew()CountCancelCurrentEdit()CurrentEndCurrentEdit()GetItemProperties()OnCurrentChanged(EventArgs)PositionRemoveAt(Int32)ResumeBinding()SuspendBinding(),和UpdateIsBinding()When you inherit from BindingManagerBase, you must override the following abstract members: AddNew(), Count, CancelCurrentEdit(), Current, EndCurrentEdit(), GetItemProperties(), OnCurrentChanged(EventArgs), Position, RemoveAt(Int32), ResumeBinding(), SuspendBinding(), and UpdateIsBinding().

构造函数

BindingManagerBase() BindingManagerBase() BindingManagerBase() BindingManagerBase()

初始化 BindingManagerBase 类的新实例。Initializes a new instance of the BindingManagerBase class.

字段

onCurrentChangedHandler onCurrentChangedHandler onCurrentChangedHandler onCurrentChangedHandler

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

onPositionChangedHandler onPositionChangedHandler onPositionChangedHandler onPositionChangedHandler

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

属性

Bindings Bindings Bindings Bindings

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

Count Count Count Count

在派生类中重写时,获取 BindingManagerBase 托管的行数。When overridden in a derived class, gets the number of rows managed by the BindingManagerBase.

Current Current Current Current

当在派生类中被重写时,获取当前对象。When overridden in a derived class, gets the current object.

IsBindingSuspended IsBindingSuspended IsBindingSuspended IsBindingSuspended

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

Position Position Position Position

当在派生类中被重写时,获取或设置绑定到该数据源的控件所指向的基础列表中的位置。When overridden in a derived class, gets or sets the position in the underlying list that controls bound to this data source point to.

方法

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

当在派生类中被重写时,向基础列表添加一个新项。When overridden in a derived class, adds a new item to the underlying list.

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

当在派生类中被重写时,取消当前编辑。When overridden in a derived class, cancels the current edit.

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

当在派生类中被重写时,结束当前编辑。When overridden in a derived class, ends the current edit.

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()

当在派生类中被重写时,获取绑定的属性说明符集合。When overridden in a derived class, gets the collection of property descriptors for the binding.

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.

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.

GetListName(ArrayList) GetListName(ArrayList) GetListName(ArrayList) GetListName(ArrayList)

当在派生类中被重写时,获取为绑定提供数据的列表的名称。When overridden in a derived class, gets the name of the list supplying the data for the binding.

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.

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.

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

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

PushData() PushData() PushData() PushData()

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

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

当在派生类中被重写时,从基础列表中删除指定索引处的行。When overridden in a derived class, deletes the row at the specified index from the underlying list.

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

当在派生类中被重写时,恢复数据绑定。When overridden in a derived class, resumes data binding.

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

当在派生类中被重写时,挂起数据绑定。When overridden in a derived class, suspends data binding.

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

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

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

当在派生类中被重写时,更新绑定。When overridden in a derived class, updates the binding.

事件

BindingComplete BindingComplete BindingComplete BindingComplete

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

CurrentChanged CurrentChanged CurrentChanged CurrentChanged

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

CurrentItemChanged CurrentItemChanged CurrentItemChanged CurrentItemChanged

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

DataError DataError DataError DataError

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

PositionChanged PositionChanged PositionChanged PositionChanged

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

适用于

另请参阅