Stopbyte

How to remove DataGridView Filter in WPF & C#?

After i filter the DataGridView to a specific value on button click using the code below:

private void btnFilter_Click(object sender, EventArgs e)
{
    string StartDate = Convert.ToDateTime(dtp_StartDate.Value).ToString("HH:mm:ss.ff");
    string EndDate = Convert.ToDateTime(dtp_EndDate.Value).ToString("HH:mm:ss.ff");
    MyBindingSource.Filter = string.Format("([{0}] >= #{1}# AND [{0}] <= #{2}#)", "Time", StartDate, EndDate);
}

Now i need to write some code to handle the event when the user decides to clear all filters, thus allowing all data grid view rows to be displayed again:

private void btnFilter_Click(object sender, EventArgs e)
{
    // I need to Remove All filters (including the one set in the previous event) Here.
}

This should be done in C#, Any Ideas?

1 Like

I think you should read Docs next time, you have done the hard work already, so simply to remove the filters apply null to the Filter property:

MyBindingSource.Filter = null;

String.Empty should work too, but i never tried it:

MyBindingSource.Filter = String.Empty;