Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I filter or search for specific rows in the datagridview, and after that I want to cancel the filter and show all the rows in the datagrideview by button(show all).

what code should I write in The button
Posted
Comments
Anisuzzaman Sumon 24-Oct-15 10:02am    
what code you tried till now.show some code.
R.M49 24-Oct-15 10:20am    
I didn't write any code for showing all the rows, only I wrote this code for Showing the rows between range of two dates selected from the datetimepickers, so what should I do if I want to display all the rows again after applying this filter ??



private void pictureBox10_Click(object sender, EventArgs e)
{
string From = Convert.ToDateTime(dateTimePicker1.Value).ToString("yyyy-MM-dd HH:mm:ss.ff");
string To = Convert.ToDateTime(dateTimePicker2.Value).ToString("yyyy-MM-dd HH:mm:ss.ff");
table1BindingSource.Filter = string.Format("([{0}] >= #{1}# AND [{0}] <= #{2}#)", "Date", From, To);

}

This should do the trick.
C#
private void buttonShowAllRows_Click(object sender, EventArgs e)
{
    table1BindingSource.Filter = null;
}

Sometimes it is actually good to read the available documentation. :-)
BindingSource.Filter Property[^]
See the default value and the remarks section.

You can also call the BindingSource.RemoveFilter[^] method.
 
Share this answer
 
v2
C#
con.Open();
               da = new OleDbDataAdapter(" select * from table name", con);
               DataSet ds = new DataSet();
               da.Fill(ds, "tablename");
               dataGridView1.DataSource = ds.Tables[0];
               ds.Tables.Clear();
               con.Close();
 
Share this answer
 
Comments
George Jonsson 25-Oct-15 18:00pm    
Which question are you answering?
Krunal Rohit 26-Oct-15 0:45am    
Though you didn't bind the data with the gridview. :doh:

-KR

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900