Link to home
Start Free TrialLog in
Avatar of hertzgordman
hertzgordmanFlag for Canada

asked on

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?
Avatar of Sancler
Sancler

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.

Roger
Avatar of hertzgordman

ASKER

Thanks

I will try this and let you know how it works
Thanks

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?
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial