2

In a .NET winforms application, how can I filter the data in my 2nd ComboBox with respect to the value selected in my 1st ComboBox?

2
  • 1
    We need to know if this is even web or windows :) Feb 13, 2010 at 14:53
  • Combo box filter on windows form In one form i got two combo boxes in which values are coming from two different tables. I want to make it such that if a user selects item from the first combo box it filters the values and shows only relavent ones in the second combo box.
    – Malou Go
    Feb 13, 2010 at 17:09

3 Answers 3

4

Assuming WinForms:

combo2.DataSource = ((IEnumerable<string>)c.DataSource)
    .Where(x => x == (string)combo1.SelectedValue);

Of course you might need to replace IEnumerable<string> with IEnumerable<YOURTYPE>.

0
0

very cryptic question - however, if you are using webforms, you may want to try using the AutoPostback property on the combobox. You can then capture the combobox onChange event and place your filtering code there.

0

You just fill the second combobox in the selectedindexchanged event of the first combobox. Quite easy, I have done it lots of times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.