A few options in the Row Filter

I am trying to put a text field as a rowfilter in an event with modified text!

The code below is used for GRID to get the corresponding Reg_Number or Customer_Name , which is entered in the text box!

Wat an amazing fact, this code directly takes a 2nd argument

(those.)
((DataTable)radGridView1.DataSource).DefaultView.RowFilter = "Reg_Number like '%" + radTextBoxControl1.Text + "%'";

tried switching lines, but no matter what I did, it ignores the first and takes the second

I tried to put AND to get both on the same line, bt did not work, plz hel me frnzz!

private void radTextBoxControl1_TextChanged(object sender, EventArgs e)
{
    try
    {
        ((DataTable)radGridView1.DataSource).DefaultView.RowFilter =
            "Customer_Name like '%" + radTextBoxControl1.Text + "%'";
        ((DataTable)radGridView1.DataSource).DefaultView.RowFilter =
            "Reg_Number like '%" + radTextBoxControl1.Text + "%'";
    }
    catch (Exception) { }
}
+5
source share
3 answers

This is because the second assignment replaces the first

myDataTable.DefaultView.RowFilter = "firstFilter";
myDataTable.DefaultView.RowFilter = "secondFilter";
// Now RowFilter is "secondFilter"

You must combine the two filters with a logical OR to get results that satisfy both conditions:

myDataTable.DefaultView.RowFilter = "firstFilter OR secondFilter";

var view = ((DataTable)radGridView1.DataSource).DefaultView;
string escapedText = radTextBoxControl1.Text.Replace("'", "''");
view.RowFilter = "Customer_Name LIKE '%" + escapedText + "%' OR " +
                    "Reg_Number LIKE '%" + escapedText + "%'";

String.Format :

view.RowFilter = String.Format("Customer_Name LIKE '%{0}%' OR Reg_Number LIKE '%{0}%'",
                               escapedText);

, # 7.0, :

view.RowFilter =
    $"Customer_Name LIKE '%{escapedText}%' OR Reg_Number LIKE '%{escapedText}%'";

, . SQL- SQL-:

SELECT * FROM myTable WHERE Name = 'Andy' Pub';

, OR, AND, , ( ).

, , . :

if (radTextBoxControl1.Text is formatted as reg_nr) {
    view.RowFilter = "Reg_Number LIKE '%" + escapedText + "%'";
} else {
    view.RowFilter = "Customer_Name LIKE '%" + escapedText + "%'";
}
+6

:

((DataTable)radGridView1.DataSource).DefaultView.RowFilter =
    "Customer_Name like '%" + radTextBoxControl1.Text + "%' AND Reg_Number like '%" + radTextBoxControl1.Text + "%'";
+2

, OR AND "Customer_Name like '%" + radTextBoxControl1.Text + "%' OR Reg_Number like '%" + radTextBoxControl1.Text + "%'";

+1

All Articles