开发者

How to filter ComboBox values in winforms

开发者 https://www.devze.com 2022-12-19 21:54 出处:网络
In a .NET winforms application, how can开发者_如何学Go I filter the data in my 2nd ComboBox with respect to the value selected in my 1st ComboBox?Assuming WinForms:

In a .NET winforms application, how can开发者_如何学Go I filter the data in my 2nd ComboBox with respect to the value selected in my 1st ComboBox?


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号