Link to home
Create AccountLog in
Avatar of JDL129
JDL129

asked on

Populate combo box using value from another combo box on the same form in C#

Hey guys!!!

This is the code I am using:

        private void btnSelect_Click(object sender, EventArgs e)
        {
            string PatNo = cboPatients.SelectedValue.ToString();
            this.dMEALL1TableAdapter.FillByDistinctPatNo(this.dME_DataSQLDataSet.DMEALL1, PatNo);
        }

I don't get any data in the destination combo box and I do have a value in PatNo.

Thanks again,

Jerry
Avatar of Anil Golamari
Anil Golamari
Flag of United States of America image

If you want to populate dropdown then you can populate second dropdown with selection changed method. you can use string ID = combobox1.SelectedValue.ToString(); to get its current selected id then you can fire a database query for this id and get values for this id and assign it to another CMB22
Avatar of JDL129
JDL129

ASKER

Hey lucky85!!!!!!!!!  Thanks for the post!!!

That sounds like just what I want but how about a little code to go with the 10,000 foot description?

I have two combo boxes: cboPatients and cboPROCODE.
cboPROCODE is bound to dMEALL1BindingSource.
 This code runs on a button click event:

            string PatNo = cboPatients.SelectedValue.ToString();
            this.dMEALL1TableAdapter.FillByDistinctPatNo(this.dME_DataSQLDataSet.DMEALL1, PatNo);
            this.cboPROCODE.Refresh();

I am getting the PatNo value but it doesn't seem to be populating the combo box.


Thanks,

Jerry
ASKER CERTIFIED SOLUTION
Avatar of Anil Golamari
Anil Golamari
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of JDL129

ASKER

Lucky85!!!!!!!  Thanks for the post!!!!!!!!