数据网格视图中的单元格双击事件 [英] Cell double click event in data grid view

查看:121
本文介绍了数据网格视图中的单元格双击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 DataGridView 事件。我有一个问题,当我双击一个单元格,两个事件,即单元格单击单元格双击正在调用事件。请给我解答为什么发生这种情况和什么解决方案。

I have two DataGridView events. I have a problem, when I double click on a cell, both the events i.e., cell click and cell double click events are being invoked. please provide me with answer why this occured and whats solution.

谢谢

推荐答案

显然,没有办法通过设置DataGridView中的属性。所以你可以使用计时器来计算是否有任何双击,如果不只是做任何你在单一的单击事件处理程序,检查代码:

Apparently there is no way to that just by setting properties in of the DataGridView. So you can use Timer to count if there was any double click, if not just do whatever you do in yous single click event handler, check the code:

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
        }

这篇关于数据网格视图中的单元格双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆