-1

I am building a window form application. I want to populate a combo box based on what the person selects from the first combo box. all my records are stored in a single database table.

Isaac Zahn
  • 11
  • 5

1 Answers1

0

Like pm100 suggested, you'll need to be registered to the first combo box's SelectedIndexChanged event and when it gets fired you'll retrieve the second combo box's values based on the first combo box SelectedText or SelectedItem property.

For example, say you'll register to the event on form load event:

cbx1.SelectedIndexChanged += Cbx1_SelectedIndexChanged;

Then when the event gets fired:

private void Cbx1_SelectedIndexChanged(object sender, EventArgs e)
{
     cbx2.Items.Clear(); // Clear to add new retreived items

     if (cbx1.SelectedIndex != -1)
     {
         // Retrieve the items based on cbx1's selected item
         var items = Repository.RetreiveItems(cbx1.SelectedText);
         cbx2.Items.AddRange(items);
     }
}

And that is basically it. You'll may want to consider retrieving the items asynchronously so that the UI will be free.

MaorB
  • 117
  • 2
  • 10