Data Grid Double-Click Event

I have two DataGridView events. I have a problem, when I double-click on a cell, events are raised, i.e. cell click and cell double click . please provide me an answer why this happened and what solution.

thanks

+6
source share
3 answers

Apparently this is not possible by simply setting the properties in the DataGridView. Thus, you can use the Timer to count, if there was a double click, if you are not just doing what you are doing in the event handler with one click, 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 } 
+1
source

With his windows problem. as far as I know, they haven’t added anything special to handle this.

You can handle it -

  • a) just do a single click on something that you would like to do before double-clicking, for example select.
  • b) if this is not an option, then start the timer in the click event. At the timer mark, perform one click action. If a double-click event occurs first, kill the timer and double-click.

The time during which you set the time must be equal to the system double-click time (which the user can specify on the control panel). It is available from System.Windows.Forms.SystemInformation.DoubleClickTime .

+1
source

You can use the RowHeaderMouseClick grid event

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

All Articles