The first trick that some people get hung up on for an application like this is dealing with displaying two sets of data-bound controls that are bound to the same set of data (the two sets of country controls), but wanting them to display different items. Your first instinct might simply be to create a single binding source for the Countries table and bind each of the controls in the two sets to their respective columns in that data source. Unfortunately, if you do this, the From Country will always reflect the same information as the To Country and vice versa. Whichever one is selected last will update the other set of controls to match it.
If you read and understood the discussion of currency managers in the last chapter, you probably already understand the problem. If both sets of controls are bound to the same data source, there is one currency manager created for that data source, and there is only one current item evenn that currency manager. Updating the current item in one of the sets of controls immediately updates the controls in the other set because they are bound to the same data source, and the currency manager for that data source keeps all controls bound to the data source synchronized to the current item. So to fix that problem you need to maintain two separate currency managers for the two sets of controls. You could get two separate copies of the data, and each would have its own currency manager as separate data sources. However, a better approach is to have two separate country binding sources, each bound to the same underlying single Countries table in the data set. This does exactly what's needed without reguiring you to maintain two copies of the data. Because each binding source encapsulates its own currency manager, even if bound to the same set of data, it gives you just the layer of indirection you need.
As shown in Listing 4.7, the revised sample application includes three binding sources corresponding to the three sets of displayed dataone for the exchange rate data, one for the From Country data, and one for the To Country data. Only one set of data is retrieved and used, and the two country binding sources are both bound to the same table in that data set.
Was this article helpful?