I'm trying to figure out some behavior in an app that I'm supporting. The snippet is:
我试图在我支持的应用程序中找出一些行为。摘录是:
foreach (DataGridViewRow pGridRow in grdEmail.Rows)
{
pGridRow.Cells[0].Value = chkSelectAll.Checked;
pCount = pGridRow.Index + 1;
}
Which is essentially trying to select all rows in a grid (check a box) when a select all checkbox is clicked.
当单击全选复选框时,本质上是尝试选择网格中的所有行(选中一个框)。
When the grid has a few rows (hundred or so) it works beautifully. However, when I have around 5000 rows in it, this thing crawls. The pGridRow.Cells[0].Value = chkSelectAll.Checked
command takes a second or so (timed by putting Console.prints above and below it).
当网格有几行(大约一百个)时,它可以很好地工作。但是,当我在其中有大约5000行时,这个东西会爬行。 pGridRow.Cells [0] .Value = chkSelectAll.Checked命令需要一秒左右(通过在其上方和下方放置Console.prints来计时)。
Any idea would be appreciated in resolving this.
在解决这个问题时,任何想法都会受到赞赏。
4 个解决方案
#1
Showing thousands of rows at once is wasteful and makes it very difficult for users to find the data they need. I would definitely recommend pagination. Your users will thank you. (Unless they have specifically requested to see 5000 at once, which seems silly.)
一次显示数千行是浪费的,并且使用户很难找到他们需要的数据。我肯定会推荐分页。您的用户会感谢您。 (除非他们特别要求一次看5000,这看起来很傻。)
#2
Try setting the properties:
尝试设置属性:
grdEmail.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
grdEmail.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
Because it seems that for the other values of these two properties the DataGridView is trying to resize the rows and columns even if you are only checking some checkboxes in the grid.
因为看起来对于这两个属性的其他值,即使您只检查网格中的某些复选框,DataGridView也会尝试调整行和列的大小。
#3
What is the point of having 5000 rows visible at once?
一次看到5000行有什么意义?
Can't this be paginated?
Can't the checkbox be sent as checked by default?
这不能分页吗?默认情况下,无法将复选框发送为已选中状态?
#4
Try modifying the underlying datasource (if any) directly instead of setting the value of the cell.
尝试直接修改基础数据源(如果有),而不是设置单元格的值。
//assuming datasetFoo.Tables(0) is the DataSource of the DataGridView
foreach (DataRow rowFoo in datasetFoo.Tables(0) {
rowFoo ("Sel") = chkSelectAll.Checked;
}
#1
Showing thousands of rows at once is wasteful and makes it very difficult for users to find the data they need. I would definitely recommend pagination. Your users will thank you. (Unless they have specifically requested to see 5000 at once, which seems silly.)
一次显示数千行是浪费的,并且使用户很难找到他们需要的数据。我肯定会推荐分页。您的用户会感谢您。 (除非他们特别要求一次看5000,这看起来很傻。)
#2
Try setting the properties:
尝试设置属性:
grdEmail.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
grdEmail.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
Because it seems that for the other values of these two properties the DataGridView is trying to resize the rows and columns even if you are only checking some checkboxes in the grid.
因为看起来对于这两个属性的其他值,即使您只检查网格中的某些复选框,DataGridView也会尝试调整行和列的大小。
#3
What is the point of having 5000 rows visible at once?
一次看到5000行有什么意义?
Can't this be paginated?
Can't the checkbox be sent as checked by default?
这不能分页吗?默认情况下,无法将复选框发送为已选中状态?
#4
Try modifying the underlying datasource (if any) directly instead of setting the value of the cell.
尝试直接修改基础数据源(如果有),而不是设置单元格的值。
//assuming datasetFoo.Tables(0) is the DataSource of the DataGridView
foreach (DataRow rowFoo in datasetFoo.Tables(0) {
rowFoo ("Sel") = chkSelectAll.Checked;
}