I have inherited some code that applies a filter to a datagrid, the filter works for but is incredibly slow when there are 500+ rows in the datagrid (it hangs with over 500, works fine with 100 rows), the filter basically says "show me everyone who has paid" or "show me everyone in X country" etc.
The list of rows that match the filter (filteredRows below) is created instantly.
if (comboBoxFilterCondition.Text == "Contains")
{
strSearchFilter += string.IsNullOrEmpty(txtFilterValue.Text) ? " IS NULL" : " LIKE '%" + txtFilterValue.Text + "%'";
}
FilterRows(strSearchFilter);
//....
private void FilterRows(string strSearchFilter)
{
DataTable table = dataGridView1.DataSource as DataTable;
if (table != null)
{
List<DataRow> filteredRows = new List<DataRow>(table.Select(strSearchFilter)); //<----Very quick to here
CurrencyManager cm = (CurrencyManager)BindingContext[dataGridView1.DataSource];
cm.SuspendBinding();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Visible = filteredRows.Contains(((DataRowView)row.DataBoundItem).Row); //<---Stuck here
}
cm.ResumeBinding(); //<----------Doesn't arrive here
//..... }
Any ideas? Thanks all