tags:

views:

26

answers:

1

hi folks,

i have both the events cellclick and celldoubleclick for a datagridview in my window forms application. The problem is that when i double click , only the cellclick event triggers, as it cannot detemine if its single click or double click.

i searched for this and found that timers could be the solution..but how to do that ? plz help

+2  A: 

You probably ought to try to find out why double-click isn't getting fired. Answering your question: you'll indeed need a timer whose Interval you set to the double-click time:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        timer1.Interval = SystemInformation.DoubleClickTime;
        timer1.Tick += delegate { timer1.Enabled = false; };
    }

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) {
        if (timer1.Enabled) {
            timer1.Enabled = false;
            // Do double-click stuff
            //...
        }
        else {
            timer1.Enabled = true;
            // Do single-click stuff
            //...
        }
    }
}
Hans Passant