数据网格视图中的单元格双击事件

我有两个DataGridView事件。 我有一个问题,当我双击一个单元格时,两个事件,即cell clickcell double click事件被调用。 请告诉我为什么这个问题和最新解决方案。

谢谢

显然,只有通过设置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 } 

它与Windows的问题。 据我所知,他们没有添加任何特殊处理它。

你可以处理这个 –

  • a)在双击之前单击一下你想要发生的事情,比如选择。
  • b)如果那不是一个选项,那么在click事件上,启动一个计时器。 在计时器勾选上,执行单击操作。 如果首先发生双击事件,请终止计时器,然后执行双击操作。

您设置时间的时间应该等于系统的双击时间(用户可以在控制面板中指定)。 它可以从System.Windows.Forms.SystemInformation.DoubleClickTime

  • 在这里查看此MSDN链接

  • 此次讨论还有Stackoverflow问题

您可以使用网格的RowHeaderMouseClick事件

  private void dgv_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { }