通过


BindingManagerBase 类

定义

管理绑定到同一数据源和数据成员的所有 Binding 对象。 此类是抽象的。

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

示例

下面的代码示例使用 BindingContext 返回特定数据源的 A BindingManagerBase 。 (本示例假定已在模块的“声明”部分中声明 myBindingManagerBase )。然后,该示例将事件委托添加到 CurrentChanged 事件和 PositionChanged 事件。 最后,该示例包含四个递增或递减属性的方法,MoveNextMovePreviousMoveLastMoveFirst并将列表的第一行或最后一行设置为。PositionPosition 列表中的最后一行通过使用 Count 属性确定。

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 窗体上的数据绑定控件的同步。 (有关将控件简单绑定到数据源的详细信息,请参阅 Binding 类。例如,假设窗体包含两 TextBox 个控件,这些控件绑定到同一数据源,但绑定到不同的列。 数据源可以是 DataTable 包含客户名称的数据源,而列可能包含名字和姓氏。 必须同步这两个控件,以便为同一客户显示正确的名字和姓氏。 继承自类的BindingManagerBase函数CurrencyManager通过维护指向数据源中当前项的指针来实现此同步。 控件 TextBox 绑定到当前项,以便显示同一行的信息。 当当前项发生更改时,通知 CurrencyManager 所有绑定控件,以便他们可以刷新其数据。 此外,可以设置属性 Position 以指定控件指向的行 DataTable 。 若要确定数据源中存在的行数,请使用该 Count 属性。

CurrencyManager这是必要的,因为数据源不一定维护当前项指针。 例如,数组和 ArrayList 对象可以是数据源,但它们没有返回当前项的属性。 若要获取当前项,请使用 Current 该属性。

它还继承自 <a0/>,它用于维护对象的当前属性,而不是数据源中当前对象的属性。 因此,尝试设置 PositionCount 属性 PropertyManager 无效。

若要创建BindingManagerBase,请使用BindingContext返回或返回的CurrencyManagerPropertyManager类,具体取决于所管理的数据源。

鼓励解决方案程序员将控件直接 BindingSource 绑定到组件,该组件充当数据源和数据连接器,同时绑定到实际目标数据源。 BindingSource 大大简化了简单和复杂的数据绑定,包括管理控件与其目标之间的货币。

实施者说明

BindingManagerBase中继承时,必须重写以下抽象成员:AddNew()、、、CountGetItemProperties()OnCurrentChanged(EventArgs)EndCurrentEdit()PositionRemoveAt(Int32)CurrentCancelCurrentEdit()、、 ResumeBinding()SuspendBinding()和。UpdateIsBinding()

构造函数

名称 说明
BindingManagerBase()

初始化 BindingManagerBase 类的新实例。

字段

名称 说明
onCurrentChangedHandler

指定事件的 CurrentChanged 事件处理程序。

onPositionChangedHandler

指定事件的 PositionChanged 事件处理程序。

属性

名称 说明
Bindings

获取所管理的绑定的集合。

Count

在派生类中重写时,获取由派 BindingManagerBase生类管理的行数。

Current

在派生类中重写时,获取当前对象。

IsBindingSuspended

获取一个值,该值指示绑定是否挂起。

Position

在派生类中重写时,获取或设置绑定到此数据源点的控件在基础列表中的位置。

方法

名称 说明
AddNew()

在派生类中重写时,向基础列表添加新项。

CancelCurrentEdit()

在派生类中重写时,取消当前编辑。

EndCurrentEdit()

在派生类中重写时,结束当前编辑。

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetItemProperties()

在派生类中重写时,获取绑定的属性描述符的集合。

GetItemProperties(ArrayList, ArrayList)

使用指定的 ArrayList值获取绑定的属性描述符的集合。

GetItemProperties(Type, Int32, ArrayList, ArrayList)

获取由此 BindingManagerBase管理的项的属性列表。

GetListName(ArrayList)

在派生类中重写时,获取提供绑定数据的列表的名称。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
OnBindingComplete(BindingCompleteEventArgs)

引发 BindingComplete 事件。

OnCurrentChanged(EventArgs)

引发 CurrentChanged 事件。

OnCurrentItemChanged(EventArgs)

引发 CurrentItemChanged 事件。

OnDataError(Exception)

引发 DataError 事件。

PullData()

将数据从数据绑定控件提取到数据源中,不返回任何信息。

PushData()

将数据从数据源推送到数据绑定控件中,不返回任何信息。

RemoveAt(Int32)

在派生类中重写时,从基础列表中删除指定索引处的行。

ResumeBinding()

在派生类中重写时,恢复数据绑定。

SuspendBinding()

在派生类中重写时,挂起数据绑定。

ToString()

返回一个表示当前对象的字符串。

(继承自 Object)
UpdateIsBinding()

在派生类中重写时,更新绑定。

活动

名称 说明
BindingComplete

在完成数据绑定操作时发生。

CurrentChanged

在当前绑定的项更改时发生。

CurrentItemChanged

当当前绑定项的状态发生更改时发生。

DataError

在由 </gt; 以无提示方式处理时发生。

PositionChanged

在属性的值 Position 发生更改后发生。

适用于

另请参阅