I got a form with multiple comboboxes, where each combobox can be set to different values. Based on the combobox value I want to create a query filter. I want to iterate through all comboboxes and add its value to the filter if it dont say “All”.
I want to do something like this:
XElement root = XElement.Load(fileName);
IEnumerable<XElement> selectedElements =
from el in root.Elements("OrderNum").Elements("ServiceJob")
where
for(int i = 0; i < combArray.GetLength(0); i++)
{
if(combArray[i].Text != "All")
{
(string)el.Element(combArray[i].AccessibleName) == combArray[i].Text &&
}
}
select el;
Any suggestions?
You can just dynamically add Where clauses as follows:
Each iteration of the for loop, takes the previous query and appends a suitable Where clause.
For ‘bonus points’ you can simplify your for loop using Linq: