DataGrid加载数据时很慢,要6秒左右才显示。。。
是因为设置了单元格颜色才变慢的吗?
int row = excelDataGridViewX.Rows.Count;//得到总行数
int cell = excelDataGridViewX.Rows[0].Cells.Count;//得到总列数
for (int i = 0; i < row; i++)//得到总行数并在之内循环
{
for (int j = 0; j < cell; j++)//得到总列数并在之内循环
{
foreach (string str in System.IO.File.ReadAllLines("Fail_Number.txt"))
{
if ((str != null && str != "") && str == excelDataGridViewX.Rows[i].Cells[j].Value.ToString())
{
this.excelDataGridViewX[j, i].Style.BackColor = Color.Red;
break;
}
}
foreach不要放到双重for循环里面去,这不变成3重for循环了吗
你调用ReadAllLines是在反复读文件,那能不慢才怪
你先把读到的内容放进List<string> LL,然后判断LL.contains(str)
三个循环嵌套,数据量大的话会很耗时的
每循环一次执行一次IO操作,你可以把IO操作放到最外面
System.IO.File.ReadAllLines("Fail_Number.txt")
三层嵌套循环,不慢才怪?一张tale 一个文本,找出文本中字符串在table的某列下标,用得着这么多循环吗?