Malou Go
Malou Go

Reputation: 57

How to filter ComboBox values in winforms

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?

Upvotes: 2

Views: 13865

Answers (3)

ThunderGr
ThunderGr

Reputation: 2367

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

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038830

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>.

Upvotes: 4

Jimbo
Jimbo

Reputation: 1

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.

Upvotes: 0

Related Questions