Avatar of rtay
rtay
Flag for United States of America asked on

C# Windows Form Search Gridview from databound combobox using foreign key

I have a windows form with a Gridview linked to a dataset.  I want to filter the gridview by a databound combobox which shows the display member but searches by the value member.  The datasource of the combobox is bound to a table that links to the gridview table with a foreign key.  So the value I need to filter by ultimately is an Int, but that would not make sense to the user, so the display member is the descriptive text value.  When writing the code behind, I get an error cannot convert from string to text.  This makes me believe that I did not configure it correctly to pass the int to the filter, and it is trying to use the text that is displayed in the combobox.  Any suggestions?

  private void button1_Click(object sender, EventArgs e)
        {
            try

                {
                    this.tbl_RateTableAdapter.FillBy(this.ds_FeedRatebyCommodity.tbl_Rate, comboBox1.Text);
                }

                catch (System.Exception ex6)

                {
                    System.Windows.Forms.MessageBox.Show(ex6.Message);
                }
            }

Open in new window

C#Windows OS

Avatar of undefined
Last Comment
Dustin Saunders

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dustin Saunders

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61