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.
Thanks
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
}
Its with Windows problem. as far i know they haven't added anything special to handle it.
You can handle this -
The amount of time you set the time for should be equal to the system's Double-Click time (which the user can specify in the control panel). It's available from System.Windows.Forms.SystemInformation.DoubleClickTime
.
Checkout this MSDN link- here
Also this discussion Stackoverflow question asked earlier
You can use RowHeaderMouseClick event of grid
private void dgv_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With