Export (0) Print
Expand All
1 out of 3 rated this helpful - Rate this topic

BindingManagerBase Class

Manages all Binding objects that are bound to the same data source and data member. This class is abstract.

For a list of all members of this type, see BindingManagerBase Members.

System.Object
   System.Windows.Forms.BindingManagerBase
      System.Windows.Forms.CurrencyManager
      System.Windows.Forms.PropertyManager

[Visual Basic]
MustInherit Public Class BindingManagerBase
[C#]
public abstract class BindingManagerBase
[C++]
public __gc __abstract class BindingManagerBase
[JScript]
public abstract class BindingManagerBase

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The BindingManagerBase enables the synchronization of data-bound controls on a Windows form that are bound to the same data source. (To simple-bind a control to a data source, add a Binding object to the control's ControlBindingsCollection, which is accessed through the DataBindings property). For example, suppose that a form contains two TextBox controls that are bound to the same data source but to different columns (The data source might be a DataTable that contains customer names, while the columns might contain the first name and last names). The two controls must be synchronized in order to display the correct first and last names together for the same customer. The CurrencyManager, which inherits from the BindingManagerBase class, accomplishes this synchronization by maintaining a pointer to the current item for the list. The TextBox controls are bound to the current item so they display the information for the same row. When the current item changes, the CurrencyManager notifies all the bound controls so that they can refresh their data. Furthermore, you can set the Position property to specify the row in the DataTable that the controls are point to. To determine how many rows exist in the list, use the Count property.

The CurrencyManager is necessary because data sources do not necessarily maintain a current-item pointer. For instance, arrays and ArrayList objects can be data sources, but they do not have a property that returns the current item. To get the current item, use the Current property.

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 list. For this reason, trying to set the Position or Count property for a PropertyManager has no effect.

To create a BindingManagerBase object, use the BindingContext class--which returns either a CurrencyManager or a PropertyManager, depending on the data source being managed.

Notes to Inheritors:  When you inherit from BindingManagerBase, you must override the following members: AddNew, Count, CancelCurrentEdit, Current, EndCurrentEdit, GetItemProperties, OnCurrentChanged, Position, RemoveAt, ResumeBinding, SuspendBinding, and UpdateIsBinding.

Example

[Visual Basic, C#, C++] The following example uses the BindingContext to return a BindingManagerBase object for a specific data source. (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. 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. The last row in the list is determined by using the Count property.

[Visual Basic] 
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

[C#] 
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;
}


[C++] 
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->get_Item(DataSet1, S"Customers.CustomersToOrders");

   // Adds delegates to the CurrentChanged and PositionChanged events.
   myBindingManagerBase->PositionChanged += 
   new EventHandler(this, &Form1::BindingManagerBase_PositionChanged);
   myBindingManagerBase->CurrentChanged +=
   new EventHandler(this, &Form1::BindingManagerBase_CurrentChanged);
}

void BindingManagerBase_PositionChanged
(Object* sender, EventArgs* /*e*/)
{
   // Prints the new Position of the BindingManagerBase.
   Console::Write(S"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(S"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;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

BindingManagerBase Members | System.Windows.Forms Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.