我正在尝试为添加到 dataGridView 的每一行添加一个计时器,并在删除一行时将其删除。
由于错误,我根本无法让计时器运行:
“System.Timers.Timer”不包含“Tick”的定义,并且找不到接受“System.Timers.Timer”类型的第一个参数的扩展方法“Tick”(您是否缺少 using 指令或程序集引用?)
当前上下文中不存在名称“myTimer_Tick”
这是我所拥有的一个例子:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Data.OleDb;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Timers;
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
System.Timers.Timer myTimer = new System.Timers.Timer();
myTimer.Interval = 30000;
myTimer.Tick += new EventHandler(myTimer_Tick);
myTimer.Enabled = true;
myTimer.Start();
}
public void MyTimer_Tick(object sender, EventArgs e)
{
MessageBox.Show("30 seconds scince you added a row");
}
private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
{
//remove a timer here that corresponds to this row,
//if row removed before timer elapsed
}
感谢您为我提供的任何帮助。