当我完成从不同文件夹到网格视图的文件填充时,如何停止我的计时器功能。 我成功地从四个不同的文件夹位置获取所有文件,我在网格视图中显示它们。但我不知道何时停止计时器。我的计时器一直在运行。我怎么能阻止这个。
我的代码段:
private void Form1_Load(object sender, EventArgs e)
{
bool authenticated = true;
if (authenticated == UserInCustomRole(strVal))// && (authenticated &= UserInSystemRole(WindowsBuiltInRole.Administrator)))
{
this.button3.Visible = true;
this.button2.Visible = false;
timer1.Start();
filter_table1();
}
if (authenticated == UserInCustomRole(strVal1))// && (authenticated &= UserInSystemRole(WindowsBuiltInRole.Administrator)))
{//
this.button3.Visible = false;
this.button2.Visible = true;
timer1.Start();
filter_table();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
//dataGridView1.Rows[i].Cells["Draft Path"].Style = new DataGridViewCellStyle { ForeColor = Color.Blue };
dataGridView1.Columns["Draft Path"].DefaultCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridView1.Columns["Draft Path"].DefaultCellStyle.ForeColor = Color.Blue;
dataGridView1.Columns["Drawing Path"].DefaultCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridView1.Columns["Drawing Path"].DefaultCellStyle.ForeColor = Color.Blue;
//dataGridView1.Rows[i].Cells["Release Path"].Style = new DataGridViewCellStyle { ForeColor = Color.Blue };
dataGridView1.Columns["Release Path"].DefaultCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridView1.Columns["Release Path"].DefaultCellStyle.ForeColor = Color.Blue;
}
dataGridView1.Columns["Archive"].Visible = false;
// backgroundWorker1.CancelAsync();
//this.Opacity = 100;
bool authenticated = true;
string textboxGroupName1 = ini.ReadValue("Action", "Fabricator");
if (authenticated == UserInCustomRole(textboxGroupName1))
{
dt.Columns["Drawing Number"].ReadOnly = true;
dt.Columns["Drawing Path"].ReadOnly = true;
dt.Columns["Release Path"].ReadOnly = true;
dt.Columns["Draft Path"].ReadOnly = true;
dataGridView1.Columns["Error"].Visible = false;
//dataGridView1.Columns["Archive"].Visible = true; //making archive visible to the fabricator
}
DataGrid dataGrid = new DataGrid();
int rowCount = dataGridView1.BindingContext[dt].Count;
label1_status.Text = "Records Found: " + (rowCount).ToString();
}
}
答案 0 :(得分:0)
如果您将数据绑定到网格,则可以这样做:
private _bindingCompleted = false;
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
_bindingCompleted = true;
// You could also stop timer here if it suits your needs
}
然后在TimerTick事件中检查绑定是否完成:
private void timer1_Tick(object sender, EventArgs e)
{
if (_bindingCompleted)
timer1.Stop();
// Rest of your code
}