For Each drow As DataGridViewRow In DgvItemList.Rows
drow.Cells("strSrNo").Value = drow.Index + 1
Next
I have more than 3500 records in DgvItemList. I just give to numbering to that records but it tool 9 to 10 minutes for that.
How to reduce this time ?
答案 0 :(得分:2)
两件事。每次更改值时,都可能导致DataGridView更新,因此在循环之前添加
DgvItemList.SuspendLayout
并在循环之后添加
DgvItemList.ResumeLayout
您也可以将循环更改为Parallel.For循环,因此您的最终代码将类似于
DgvItemList.SuspendLayout
Parallel.For(0, DgvItemList.Rows.Count, Sub(index As Integer)
DgvItemList.Rows(index).Cells("strSrNo").Value = DgvItemList.Rows(index).Index + 1
End Sub)
DgvItemList.ResumeLayout
首先尝试使用Suspend and Resume布局。您可能无法从并行化中获得大量改进。值得一试。