问题描述
我有一个WinForms应用程序,具有约1000行(绑定)和50列的一个DataGridView。隐藏列需要整整2秒。当我想隐藏大约一半的行,这成为了问题。
I have a DataGridView in a Winforms app that has about 1000 rows (unbound) and 50 columns. Hiding a column takes a full 2 seconds. When I want to hide about half the rows, this becomes a problem.
private void ShowRows(string match)
{
this.SuspendLayout();
foreach (DataGridViewRow row in uxMainList.Rows)
{
if (match == row.Cells["thisColumn"].Value.ToString()))
{ row.Visible = false; }
else
{ row.Visible = true; }
}
this.ResumeLayout();
}
我通过增加 Console.WriteLine(DateTime.Now)
各地的行动,而 row.Visible = FALSE 加做了一些测试code>绝对是慢一点。我失去了一些东西很明显,如设置
IsReallySlow = FALSE
?还是我先走,并启用虚拟模式和code了必要的事件?
I did some testing by adding by addingConsole.WriteLine(DateTime.Now)
around the actions, androw.Visible = false
is definitely the slow bit. Am I missing something obvious, like setting IsReallySlow = false
? Or do I have to go ahead and enable Virtual Mode and code up the necessary events?
推荐答案
它看起来对我来说,你应该使用行过滤器代替。
It looks to me like you should be using row filters instead.
尝试使用一个数据视图作为您的绑定源,并使用DataView.RowFilter隐瞒你所选择的行或显示行。
Try using a DataView as your binding source and use DataView.RowFilter to hide rows or show rows of your choosing.
DataGridView myGridView = new DataGridView();
DataView myDataView = myTable.DefaultView;
myGridView.DataSource = myDataView; // DataView that allows row filtering
myDataView.RowFilter = string.Format("thisColumn <> '{0}'",match); // this will hide all rows where "thisColumn" = match
这篇关于在DataGridView中隐藏行很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!