The CurrencyManager Object

The CurrencyManager Object

The CurrencyManager object is used to keep data-bound controls synchronized with one another, essentially ensuring that each shows data from the same record. The CurrencyManager object accomplishes this magic by managing a collection of the bound data supplied by a single data source.

Because more than one data source can be associated with a form, the BindingContext object manages all the CurrencyManager objects for any particular form. Not only forms, but also all container controls have at least one BindingContext object to manage their CurrencyManager objects.

Record Navigation

We need to understand how to bind controls to data sources because within Visual Basic .NET, data sources do not have any idea of a control's position within the data source. Unlike classic ADO, which maintained the current record and provided ways for you to navigate to other records, we need to use a different approach when working with ADO.NET. Some Visual Basic .NET programmers might be surprised to see that the data no longer "knows" where the current record itself is. ADO.NET doesn't use the notion of a cursor in our disconnected recordsets. But there is an upside to this approach. Because of the absence of a cursor, you can have multiple positions set on the same store of data.

When you need to know where you are in a data source, you must examine the Position property of the CurrencyManager object. Just remember that the term currency is used to refer to the currentness of position within a data structure. You can easily use the Position property of the CurrencyManager class to determine the currency of all controls bound to the same CurrencyManager object.

Consider the two text boxes, tbTitle and tbEmployeeID, mentioned previously. These text boxes are bound to the same table, but they are bound to different columns. When the Position property of the common CurrencyManager object is set to the fourth position within that data source (corresponding to the fifth record because the position is zero-based), both controls display the appropriate values (the fifth "Title" and the fifth "EmployeeID") for that position in the table.



Coding Techniques for Microsoft Visual Basic. NET
Coding Techniques for Microsoft Visual Basic .NET
ISBN: 0735612544
EAN: 2147483647
Year: 2002
Pages: 123
Authors: John Connell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net