Cell Double Click event is not running. only Cellclick event gets executed
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
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
            //...
        }
    }
}
I established a little solution for this: add timer in your form
public Form1()
{
     timer1.Interval = SystemInformation.DoubleClickTime;
}
bool double_click = false;
//
DataGridViewCellEventArgs sendedEvent = null;
private void DatagridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
   double_click = true;
   sendedEvent = e;
}
private void DatagridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    sendedEvent = e;
    //
    timer1.Enabled = true;
    //
    timer1.Start();
 }
 private void timer1_Tick(object sender, EventArgs e)
 {
    if (!double_click)
    {
        // DO your simple click stuff and USE sendedEvent if needed
    }
    else
    {
         double_click = false;
         // DO your Doubleclick stuff and USE sendedEvent if needed
    }
    timer1.Stop();
    timer1.Enabled = false;
  }
Hope this will help ^^
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论