Adding combo box for form created with data wizard

I have created a form using the data wizard.  It works fine.

Want to change one control to a combo box.  I am able the write the code that loads the combo box from the database.
I also bound the combo box to the dataset for the form.

The problem is that the combo box is not in synch with the form.

1.  Is there any trick to bind it properly?
2.  Do I need to add event code to have the combo box reflect the data in the current record?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'll assume that your data set-up is something like this.  The controls on your form are bound to a main table.  In that there is a reference (foreign key) to a subsidiary table.  It is the contents of that subsidiary table that you want the combobox to display.

On that basis, the bindings you want would be something like this

   MyCombo.DataSource = SubsidiaryTable
   MyCombo.DisplayMember = "Description" 'ie the field in the sub table that you want displayed
   MyCombo.ValueMember = "ID" 'ie the Primary Key field in the sub table
   MyCombo.DataBindings.Add("SelectedValue", MainTable, "ForeignKey") 'ie the field in the main table that represents the appropriate item in the sub table

If my assumptions are correct, and you can translate the above code OK for your set up, you shouldn't need any additional code to keep the combobox in synch with the other controls on the form.

hertzgordmanAuthor Commented:

I will try this and let you know how it works
hertzgordmanAuthor Commented:

This helped.

It turns out I was not binding the combo to the correct table (i.e.MainTable).

I used the designer to do the bindings.  Where were I put the above code if I wanted to do this as per above?
Where were I put the above code if I wanted to do this as per above?

Probably in your Form's Load sub; probably best after you have filled your datatables.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.