PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Binding two comboboxes to the same source

Reply

Binding two comboboxes to the same source

 
Thread Tools Rate Thread
Old 02-08-2005, 02:21 PM   #1
Brian Smith
Guest
 
Posts: n/a
Default Binding two comboboxes to the same source


I have 2 combos on a form which require to have the same set of values
in the dropdown, but bind to different values in the main DataTable.

So I set the datasources thus:
cboOldProvider.ComboBoxControl.DataSource = ds.ServiceProviders ;
cboOldProvider.ComboBoxControl.DisplayMember = "Description" ;
cboOldProvider.ComboBoxControl.ValueMember = "ProviderID" ;

cboNewProvider.ComboBoxControl.DataSource = ds.ServiceProviders ;
cboNewProvider.ComboBoxControl.DisplayMember = "Description" ;
cboNewProvider.ComboBoxControl.ValueMember = "ProviderID" ;

The I add bindings to values in the main datatable:
cboOldProvider.DataBindings.Add("SelectedValue", ds.LineItems,
"OldProviderID") ;
cboNewProvider.DataBindings.Add("SelectedValue", ds.LineItems,
"NewProviderID") ;

BUT, when I choose any value in either combobox, the other combo changes
to the same value. I can't make them different.
What is wrong with my code????

brian smith
  Reply With Quote
Old 02-08-2005, 02:44 PM   #2
Brian Smith
Guest
 
Posts: n/a
Default Re: Binding two comboboxes to the same source

OK, found my answer - the DataSources MUST be different.
so:
cboNewProvider.ComboBoxControl.DataSource = ds ;
cboNewProvider.ComboBoxControl.DisplayMember =
"ServiceProviders.Description" ;
cboNewProvider.ComboBoxControl.ValueMember =
"ServiceProviders.ProviderID" ;

God knows what you do if you have more than two!

brian

Brian Smith wrote:
> I have 2 combos on a form which require to have the same set of values
> in the dropdown, but bind to different values in the main DataTable.
>
> So I set the datasources thus:
> cboOldProvider.ComboBoxControl.DataSource = ds.ServiceProviders ;
> cboOldProvider.ComboBoxControl.DisplayMember = "Description" ;
> cboOldProvider.ComboBoxControl.ValueMember = "ProviderID" ;
>
> cboNewProvider.ComboBoxControl.DataSource = ds.ServiceProviders ;
> cboNewProvider.ComboBoxControl.DisplayMember = "Description" ;
> cboNewProvider.ComboBoxControl.ValueMember = "ProviderID" ;
>
> The I add bindings to values in the main datatable:
> cboOldProvider.DataBindings.Add("SelectedValue", ds.LineItems,
> "OldProviderID") ;
> cboNewProvider.DataBindings.Add("SelectedValue", ds.LineItems,
> "NewProviderID") ;
>
> BUT, when I choose any value in either combobox, the other combo changes
> to the same value. I can't make them different.
> What is wrong with my code????
>
> brian smith

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off