private async void filterTextBox_TextChanged(object sender, EventArgs e) { var text = filterTextBox.Text.Trim(); if (_LastFilterText != text) { _LastFilterText = text; await Task.Delay(250); filterTextBox_TextChanged(sender, e); return; } var isEmpty = text.IsNullOrEmpty(); clearFilterButton.Enabled = !isEmpty; //var cm = BindingContext[ DGV.DataSource ] as CurrencyManager; //cm?.SuspendBinding(); DGV.SuspendDrawing(); try { if (isEmpty) { foreach (var row in DGV.Rows.Cast <DataGridViewRow>()) { row.Visible = true; } } else { foreach (var row in DGV.Rows.Cast <DataGridViewRow>()) { if (!row.IsNewRow) { var value = row.Cells[0].Value?.ToString(); row.Visible = ((value != null) && (value.IndexOf(text, StringComparison.InvariantCultureIgnoreCase) != -1)); } } } } finally { //cm?.ResumeBinding(); DGV.ResumeDrawing(); } }
private async void filterTextBox_TextChanged(object sender, EventArgs e) { var text = filterTextBox.Text.Trim(); if (_LastFilterText != text) { await Task.Delay(250); _LastFilterText = text; filterTextBox_TextChanged(sender, e); return; } var isEmpty = text.IsNullOrEmpty(); clearFilterButton.Visible = !isEmpty; DGV.SuspendDrawing(); try { if (isEmpty) { foreach (var row in DGV.Rows.Cast <DataGridViewRow>()) { row.Visible = true; } } else { foreach (var row in DGV.Rows.Cast <DataGridViewRow>()) { if (!row.IsNewRow) { row.Visible = (row.Cells[0].Value?.ToString()).ContainsIgnoreCase(text); } } } } finally { DGV.ResumeDrawing(); } }