Hi, I'm hopeing someone will be willing to help me with somthing that is probably quite simple.

I'm trying to bind a combobox to a data table, however it is supposed to be a foriegn key field, as such I need the items list to be populated from a different table.

This would be simple if I were doing it at design time, however I am trying to bind at run time. The code I have, simply binds the text to the current record, using the binding source.

I have not been able to get the items list to populate.

private void tbcOPControls_Enter(object sender, EventArgs e)
            if (isManager)
                hasChanged = false;
                dbDataSetXSD dsTheData = new dbDataSetXSD();
                //instantiate the table adapter for the staff table
                dbDataSetXSDTableAdapters.tblStaffTableAdapter dsTblStaff = new Cinemax.dbDataSetXSDTableAdapters.tblStaffTableAdapter();
                //Create a binding source
                bsTblStaff = new BindingSource();
                //Attatch the binding source to the table adapter
                bsTblStaff.DataSource = dsTheData.tblStaff;
                //Fill the table adapter
                //Create data bindings
                txtStaffID.DataBindings.Add(new Binding("Text", bsTblStaff, "StaffID"));
                cmbStaffTitle.DataBindings.Add(new Binding("Text", bsTblStaff, "Title"));

                txtStaffSurname.DataBindings.Add(new Binding("Text", bsTblStaff, "Surname"));
                txtStaffFirstName.DataBindings.Add(new Binding("Text", bsTblStaff, "FirstName"));
                txtStaffAddress.DataBindings.Add(new Binding("Text", bsTblStaff, "AddressLine1"));
                txtStaffTown.DataBindings.Add(new Binding("Text", bsTblStaff, "Town"));
                txtStaffCounty.DataBindings.Add(new Binding("Text", bsTblStaff, "County"));
                txtStaffPostCode.DataBindings.Add(new Binding("Text", bsTblStaff, "Postcode"));
                txtStaffRole.DataBindings.Add(new Binding("Text", bsTblStaff, "StaffRole"));
                cmbStaffBoss.DataBindings.Add(new Binding("Text", bsTblStaff, "BossID"));
                cmbStaffBoss.DataSource = dsTheData;
                cmbStaffBoss.DisplayMember = dsTheData.tblCinema.ManagerIDColumn.ToString();
                cmbStaffCinema.DataBindings.Add(new Binding("Text", bsTblStaff, "CinemaID"));
                txtStaffUserID.DataBindings.Add(new Binding("Text", bsTblStaff, "UserID"));
                txtStaffPassword.DataBindings.Add(new Binding("Text", bsTblStaff, "Password"));

                btnPrevious.Visible = true;
                btnNext.Visible = true;

the binding works fine for passing throw the records, is just the combo boxes that are a problem. Please can anyone help?

Thanks for taking the time to read.

If you can do it at design time you can do it at run time.
Make it work at design time, look in the XXX.Designer.cs file how it is done and act accordingly at run time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.