【发布时间】:2023-03-18 13:37:02
【问题描述】:
excel = Workbook.Open("1.xls");
sheeticerik = excel.Worksheets[0];
for (int k = 0; k < sutun; k++)
for (int i = 0; i < satir; i++)
{
string a = sheeticerik.Cells[i, k].StringValue;
if (a.Contains("X"))
{
dataGridView1.Rows[x1].Cells[y1].Style.BackColor = System.Drawing.Color.Red;
System.Threading.Thread.Sleep(1000);
dataGridView1.Refresh();
}
}
我想每秒打印颜色到datagridview。我写了这段代码。但它不起作用。因为程序loop.countX1000秒等待并立即打印颜色。不是连续打印。我该怎么办?
解决方案[编辑]:
-在表单中添加 Timer 控件。 (它在组件类别中)
-将其Interval属性设置为45000(值代表毫秒)
-在表单设计器中或在代码中的某处将计时器的 Enabled 属性设置为 True。
-为定时器的Tick事件添加处理程序(可以通过双击定时器来获取)
-在 Tick 处理程序中,更新您的 dataGridView
private void timer1_Tick(object sender, EventArgs e)
{
// Update DataGridView
}
并使用,timer1.Start();...
【问题讨论】:
-
你走错路了。您需要一个计时器来更新数据网格。
-
谢谢你的人......定时器的工作!
标签: c# datagridview