Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Binding two comboboxes to the same source

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Smith - 02 Aug 2005 14:21 GMT
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
Brian Smith - 02 Aug 2005 14:44 GMT
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

> 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.
[quoted text clipped - 19 lines]
>
> brian smith

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.