Have problems in filtering binding source

Viewed 43

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))
        {
            //MyLoad();
            bindingSource1.Filter = string.Empty;
            timeFilter.CustomFormat = " ";
            timeFilter.Text = null;
            timeFilter.Format = DateTimePickerFormat.Custom;
            gridFilter.Update();
            gridFilter.Refresh();
        }
    }

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.

0 Answers
Related