Adding combo box for form created with data wizard

Posted on 2006-04-15
Last Modified: 2010-04-23
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?
Question by:hertzgordman
    LVL 34

    Expert Comment

    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.


    Author Comment


    I will try this and let you know how it works

    Author Comment


    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?
    LVL 34

    Accepted Solution

    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.


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now