Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datagridview row filter

I am using DataView and RowFilter. Only one column is filtering, but I want all columns to be filtered.

I would like to search for a word in the text box to make this filter.

DataView dv = dt.DefaultView;

if (e.KeyChar == (char)13)
{
    dv.RowFilter = string.Format("Name LIKE '%{0}%'" ,textBox1.Text );
    //  dv.RowFilter = string.Format("Date LIKE '%{0}%'", textBox1.Text);
}

The columns headers name = Name, Date, and so on.

like image 588
Simkyujin Avatar asked Oct 25 '25 12:10

Simkyujin


2 Answers

Format should be like this for multiple columns;

dv.RowFilter = "Column1 = " + value1 + " AND Column2 = " + value2;

According to your scenario;

dv.RowFilter = string.Format("Name LIKE '%{0}%' AND Date = {1}" ,textBox1.Text, DateValue );
like image 96
Irshad Avatar answered Oct 28 '25 04:10

Irshad


(dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("Name = '{0}'", TextBoxForSearch.Text);
like image 39
user8682754 Avatar answered Oct 28 '25 04:10

user8682754