Cell double click event in data grid view
Solution 1
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
}
Solution 2
Its with Windows problem. as far i know they haven't added anything special to handle it.
You can handle this -
- a) just make single click something you'd want to happen before a double click, like select.
- b) if that's not an option, then on the click event, start a timer. On the timer tick, do the single click action. If the double-click event occurs first, kill the timer, and do the double click action.
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
Solution 3
You can use RowHeaderMouseClick event of grid
private void dgv_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
}
AhmedShawky
Ahmed Shawky , pixelware co-founder Daily skills HTML, CSS, Javascript Ruby On Rails , MySQL WPF , MS SQL Server Programming languages C++,C# Java Ruby Operating Systems Windows Linux “Ubuntu Database MySQL Oracle database MS SQL Server SQLite Web design/development Ruby On Rails HTML,XML Javascript ,JSON, AJAX Ember.js CSS, LESS, SASS Programming tools and Frameworks Eclipse IDE Geany Editor GIT versioning system Netbeans IDE SVN versioning system MS Visual Studio Sublime Text Specialties : Ruby On Rails , HTML, CSS, JavaScript , C#, web development.
Updated on July 02, 2022Comments
-
AhmedShawky over 1 year
I have two
DataGridView
events. I have a problem, when I double click on a cell, both the events i.e.,cell click
andcell double click
events are being invoked. please provide me with answer why this occured and whats solution.Thanks