当我在dataGridView中选中一个复选框时,我选中的复选框会自动变为false,因为我每秒刷新一次dataGridView。我想发生的是选中dataGridView复选框时取消每秒刷新。
这是我的代码:
private void UpdateVisitors_Load(object sender, EventArgs e)
{
//Realtime refresh
refresher.Interval = (1 * 1000); // 10 secs
refresher.Tick += new EventHandler(refresh);
refresher.Start();
}
private void refresh(object sender, EventArgs e)
{
refreshLocal();
}
更新 这是我用来刷新dataGridView的refreshLocal代码
void refreshLocal()
{
dgvLocal.Rows.Clear();
connection.Close();
connection.Open();
SqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "Select * from tbl_Registration ORDER BY [ID] DESC;";
SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
myID = dr["ID"].ToString();
category = dr["Category"].ToString();
repname = dr["Representative"].ToString();
if (dr["City/Province"].ToString() == "")
{
city = dr["Province"].ToString();
}
else
{
city = dr["City/Province"].ToString();
}
pax = dr["Pax"].ToString();
male = dr["Male"].ToString();
female = dr["Female"].ToString();
students = dr["Students"].ToString();
ar = dr["AR Users"].ToString();
date = dr["Date & Time Added"].ToString();
dgvLocal.Rows.Add(false, myID, category, repname, city, pax,students, ar, date);
}
connection.Close();
}
答案 0 :(得分:1)
您需要绑定到DataGridView的事件CellValueChanged,并在处理程序内部,根据复选框的值停止计时器。
SELECT ID, MIN(UniqueValue)
FROM Sample_Table
WHERE ID in ('Bob', 'Sam', 'Kyle', 'Jordan')
GROUP BY ID;