none
Advanced filter RRS feed

  • Question

  • Hi all,

    I m using c sharp and i have to build a windows form to support advanced filter. i m using a binding source and i have to set the filter string programmatically.

    form has 5 combos to show fields of the table,

    5 combos containing values as 'Contains','equals to','begin with','end with','greater than' etc (criteria)

    5 text boxes to enter value,

    4 group boxes with containing two radio buttons as 'AND' and 'OR'

    After selecting any number of combos and set values and click the filter button, the grid should be filtered.

    User can select one combo or multiple combos to set the filter. How may i do this? if user select a value such as 'contains ' i should have to set the filter string such as 'LIKE %'.

    Tuesday, April 12, 2011 12:14 PM

Answers

  •  

    Hi Anu,

     

    Welcome to the MSDN forum!

     

    It is a complex logical problem but not a development problem.

    I suggest write the logical method in the button Click event:

    string SQLCmd=string.Empty;

                SQLCmd = "select * from TableName where Column ";

                switch (this.comboBox1.SelectedText)

                {

     

                    case "equals to":

                        SQLCmd += " = ";break;

                    case "greater than":

                        SQLCmd += " > "; break;

                        //...

                    default: SQLCmd = "select * from TableName "; break;

                }

     

    I hope this can help you resolve your problem.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Wednesday, April 20, 2011 2:37 AM
    Thursday, April 14, 2011 10:15 AM