One data source, two combobox lookups

  • Thread starter Scudder Consulting
  • 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
 
R

Ross Culver

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
 
J

Jack Jackson

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.
 
S

Scudder Consulting

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
 
S

Scudder Consulting

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top