Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

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?
0
hertzgordman
Asked:
hertzgordman
  • 2
  • 2
1 Solution
 
SanclerCommented:
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
0
 
hertzgordmanAuthor Commented:
Thanks

I will try this and let you know how it works
0
 
hertzgordmanAuthor Commented:
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?
0
 
SanclerCommented:
>>
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.

Roger
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now