in another topic, I came across this very elegant solution Darin Dimitrov to filter one ComboBox DataSource with the selection of another ComboBox:
how to filter in the combobox combobox using C #
combo2.DataSource = ((IEnumerable<string>)c.DataSource)
.Where(x => x == (string)combo1.SelectedValue);
I would like to do a similar thing, but instead of filtering with a second drop-down, I would like to filter the text of the TextBox. (In principle, instead of choosing from the second ComboBox, the user simply enters his filter into the TextBox). However, this was not as direct as I had hoped. I tried things like the following, but failed unsuccessfully:
cbWohndresse.DataSource = ((IEnumerable<DataSet>)ds)
.Where(x => x.Tables["Adresse"].Select("AdrLabel LIKE '%TEST%'"));
cbWohndresse.DisplayMember = "Adresse.AdrLabel";
cbWohndresse.ValueMember = "Adresse.adress_id";
ds is a DataSet that I would like to use as a filtered DataSource. An “address” is one DataTable in this DataSet. It contains the DataColumn "AdrLabel". Now I would like to display only those "AdrLabel" that contain a string from user input. (Currently% TEST% is replacing textbox.text.)
The above code does not work because lambda expression does not return Bool. But I'm sure there are other problems (which type should I use for IEnumerable? Now it's a DataSet, but Darin used a String. But how could I convert a DataSet to a string?
Yes, I'm just as new as he is, my experience is “empty” and public. So please forgive me for my rather silly questions.
Your help is greatly appreciated because I cannot solve this problem myself (I have tried it for a long time).
!
Pesche
P.S. Linq ComboBox ( ). Linq, oldstyle Ado.NET(ds SqlDataAdapter), .