Я унаследовал некоторый код, который применяет фильтр к datagrid, фильтр работает, но невероятно медленный, когда в datagrid есть 500+ строк (он зависает с более чем 500, отлично работает со 100 строками), фильтр в основном говорит «показать мне всех, кто заплатил» или «показать мне всех в X стране» и т. д.C# Почему этот цикл настолько медленный?
Список строк, соответствующих фильтру (отфильтрованный ниже), создается мгновенно.
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
// ..... }
Любые идеи? Спасибо всем
Is Hashset in .net 3.5? Я использую .net 2.0. Спасибо – 2009-06-08 00:07:50
Да, это .NET 3.5 вещь – AgileJon