我有两个DataGridView
事件。我有一个问题,当我双击一个单元格时,这两个事件,即cell click
and cell double click
正在调用事件。请向我提供答案为什么会发生这种情况以及解决方案是什么。
Thanks
显然,仅通过设置 DataGridView 的属性是无法做到这一点的。因此,您可以使用 Timer 来计算是否有双击,如果没有,只需在单击事件处理程序中执行任何操作,请检查代码:
System.Windows.Forms.Timer t;
public Form1()
{
InitializeComponent();
t = new System.Windows.Forms.Timer();
t.Interval = SystemInformation.DoubleClickTime - 1;
t.Tick += new EventHandler(t_Tick);
}
void t_Tick(object sender, EventArgs e)
{
t.Stop();
DataGridViewCellEventArgs dgvcea = (DataGridViewCellEventArgs)t.Tag;
MessageBox.Show("Single");
//do whatever you do in single click
}
private void dataGridView1_CellClick_1(object sender, DataGridViewCellEventArgs e)
{
t.Tag = e;
t.Start();
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
t.Stop();
MessageBox.Show("Double");
//do whatever you do in double click
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)