在大型 datagridview 数据源中实现类似 excel(性能方面)的过滤
Implement filtering like excel (performance wise) in large datagridview datasource
这个问题是 Suggestions for more efficient filtering on large datagridview datasources 的一个单独问题。所以现在我在大型数据源(220k 行)上的过滤速度很慢。我过滤的方式是通过绑定源:
mBindingSource.Filter = Filter;
这很慢,因为它可能遍历数据表的所有行。
当我尝试在 Excel 中过滤相同大小的数据时,过滤速度快了很多倍。我想知道是否有人知道 Excel 如何实现其过滤,或者可以为我指出正确的方向。也许一小段代码也有帮助。
一旦你有一个 dataGridView
满行,过滤就非常快。您的问题可能是您在应用过滤器之前重新加载 dataGridView
。
我用超过 800K 行的数据库进行了测试,过滤时间不到一秒(也许 Excel 需要更长的时间)。
我是这样测试的:
从数据源 window 中取出 table 并将其拖放到您的 Form
上。在我的例子中,我选择了一个名为 Products.
的 table
这会在您的 Form
上创建一个名为 productsDataGridView
的 dataGridView
,因此 CS 代码如下所示:
private void button1_Click(object sender, EventArgs e)
{
BindingSource bs = (BindingSource)productsDataGridView.DataSource;
bs.Filter = string.Format("SerialNumber Like '%{0}%'", textBox1.Text);
productsDataGridView.DataSource = bs;
}
在我的例子中,每次我按下 button1
时,超过 820,000 行的 productsDataGridView
都会在不到一秒的时间内被过滤掉。
希望这对您调试代码有所帮助。
这个问题是 Suggestions for more efficient filtering on large datagridview datasources 的一个单独问题。所以现在我在大型数据源(220k 行)上的过滤速度很慢。我过滤的方式是通过绑定源:
mBindingSource.Filter = Filter;
这很慢,因为它可能遍历数据表的所有行。
当我尝试在 Excel 中过滤相同大小的数据时,过滤速度快了很多倍。我想知道是否有人知道 Excel 如何实现其过滤,或者可以为我指出正确的方向。也许一小段代码也有帮助。
一旦你有一个 dataGridView
满行,过滤就非常快。您的问题可能是您在应用过滤器之前重新加载 dataGridView
。
我用超过 800K 行的数据库进行了测试,过滤时间不到一秒(也许 Excel 需要更长的时间)。
我是这样测试的:
从数据源 window 中取出 table 并将其拖放到您的 Form
上。在我的例子中,我选择了一个名为 Products.
这会在您的 Form
上创建一个名为 productsDataGridView
的 dataGridView
,因此 CS 代码如下所示:
private void button1_Click(object sender, EventArgs e)
{
BindingSource bs = (BindingSource)productsDataGridView.DataSource;
bs.Filter = string.Format("SerialNumber Like '%{0}%'", textBox1.Text);
productsDataGridView.DataSource = bs;
}
在我的例子中,每次我按下 button1
时,超过 820,000 行的 productsDataGridView
都会在不到一秒的时间内被过滤掉。
希望这对您调试代码有所帮助。