6

我有两个DataGridView事件。我有一个问题,当我双击一个单元格时,事件 iecell clickcell double click事件都被调用。请告诉我为什么会发生这种情况以及有什么解决方案。

谢谢

4

3 回答 3

1

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

你可以处理这个 -

  • a) 只需单击您希望在双击之前发生的事情,例如选择。
  • b)如果这不是一个选项,那么在点击事件上,启动一个计时器。在计时器滴答声中,执行单击操作。如果先发生双击事件,则终止计时器,然后执行双击动作。

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

于 2012-11-19T13:04:06.450 回答
1

显然,仅通过在 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
        }
于 2012-11-19T13:16:25.227 回答
1

您可以使用网格的 RowHeaderMouseClick 事件

    private void dgv_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
 {

    }
于 2013-05-23T05:02:22.267 回答