Have problems in filtering binding source

Issue

This Content is from Stack Overflow. Question asked by hank

I have a datagridview and it’s source is a bindingSource. I filter them by Id, name and date.
enter image description here

Also have clear button for clearing filters.

private void b_clear_Click(object sender, EventArgs e)
        {

                txt_filterNum.Clear();
                txt_filterName.Clear();
                if (File.Exists(inputpath))
                {
                    Simulator simRead = new Simulator(inputpath);
                    DataTable dt = simRead.MakeDataTable();
                    bindingSource1.DataSource = dt;
                    gridView.DataSource = bindingSource1;
                    timeFilter.CustomFormat = " ";
                    timeFilter.Text = null;
                    timeFilter.Format = DateTimePickerFormat.Custom;
                }                
        }

I’m having a really hard time filtering this gridview and clearing the filters.
Here I add my filter too.

 bindingSource1.Filter = $"Flight_Date = #{timeFilter.Value:M/dd/yyyy}# AND {gridFilter.Columns[indexRoleName].HeaderText} LIKE '%{txt_filterName.Text}%' AND {gridFilter.Columns[indexRoleNum].HeaderText} LIKE '%{txt_filterNum.Text}%'";

I call it in textboxes_changed and datetimePicker_valuechanged.

I can’t filter the values properly, When I try to delete the filtering I have done, I can not get a reset in the datagridview.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?