One data source, two combobox lookups

  • Thread starter Thread starter Scudder Consulting
  • Start date Start date
S

Scudder Consulting

In a database there is a County lookup table that is used to provide the
county names for display. The Contact table only stores a numeric code for
county. I have two county ComboBox controls on the form. One is for the
home address and the other is for the business address. Both ComboBox
controls use the same lookup table. The problem is that they stay in sync.
It seems to me that I need to maintain two cursors, one for each ComboBox.

Do I need to have two BindingSource controls for the County table or is
there a better way to do it?

Roger
 
Yes. Remember, your datasets are separate from the underlying tables (much
like a recordset), so when you fill the table and enumerate through the
dataset, you're working with the dataset, not the source table. You'll have
to create to datasets.

Ross
 
No, two DataSets are not necessary. A DataSet has no concept of
current position, that is handled by an object like CurrencyManager or
BindingSource. By default all controls bound to a source will use the
form's default currency manager and therefore will sync to the same
record.

In 2.0 the easiest way to fix this is to create a separate
BindingSource for one of the comboboxes. Set its DataSource to the
DataTable and bind the combobox to the BindingSource.
 
In 2.0 the easiest way to fix this is to create a separate
BindingSource for one of the comboboxes. Set its DataSource to the
DataTable and bind the combobox to the BindingSource.

That is what I thought since a BindingSource encapsulates what is
essentially a cursor object. I just wanted to make sure there wasn't a
better way.

Thanks to both who commented!
Roger
 
Actually I ran into some trouble by simply adding another BindingSource.
What I found out was that it is possible to have more than one
BindingManagerBase for a single data source. The controls need to be
within a group object, which is perfect for me since I already have home
address and business address in their own groupBox controls.

Check MSDN documentation for BindingContext class for more information.

Roger
 
Back
Top