Hi,
I have more than 40 controls (checkbox, textbox, combobox...) on a form. I am already aware of "append to criteria string and create the filter from scratch on every event handler of the controls" scenario. I have no problem with adding conditions to the filter string when the conditions are all 'AND' or all 'OR'. But the problem starts when I have to create a criteria with lots of ORs and ANDs logic which require parenthesis too to give me the desire search results. I find appending to the filter string with just (criteria = criteria & " AND ") is not a real world approach, for example, lest say we need to search for married persons whose age is either 30 or 40
The (criteria = criteria & " AND ") won't work here of course, you can't say in the filter:
criteria="Age='30' AND Age='40' AND Rel='Married'"
you have to say:
criteria="(Age='30' OR Age='40') AND Rel='Married"
Please notice the parenthesis too, if we omit them we will end up with married persons who are 40 years old, and not married ones who are 30, which is is not what we are searching for and that's because of the precedence of AND operator.
I can build the criteria manually (hard coded) but I don't want this of course, I want the criteria to be built problematically by the event handlers of the controls, but the ORs and ANDs and the parenthesis are too much for me, I would struggle to build a huge criteria manually with lots of logic, so how if I build the criteria problematically!
Is there an easier way to filter a bindingsource based on lots of check/text/comboboxes?
Any help or enlightenment would be very appreciated
I have more than 40 controls (checkbox, textbox, combobox...) on a form. I am already aware of "append to criteria string and create the filter from scratch on every event handler of the controls" scenario. I have no problem with adding conditions to the filter string when the conditions are all 'AND' or all 'OR'. But the problem starts when I have to create a criteria with lots of ORs and ANDs logic which require parenthesis too to give me the desire search results. I find appending to the filter string with just (criteria = criteria & " AND ") is not a real world approach, for example, lest say we need to search for married persons whose age is either 30 or 40
The (criteria = criteria & " AND ") won't work here of course, you can't say in the filter:
criteria="Age='30' AND Age='40' AND Rel='Married'"
you have to say:
criteria="(Age='30' OR Age='40') AND Rel='Married"
Please notice the parenthesis too, if we omit them we will end up with married persons who are 40 years old, and not married ones who are 30, which is is not what we are searching for and that's because of the precedence of AND operator.
I can build the criteria manually (hard coded) but I don't want this of course, I want the criteria to be built problematically by the event handlers of the controls, but the ORs and ANDs and the parenthesis are too much for me, I would struggle to build a huge criteria manually with lots of logic, so how if I build the criteria problematically!
Is there an easier way to filter a bindingsource based on lots of check/text/comboboxes?
Any help or enlightenment would be very appreciated