DataGridView: detect click on empty cells (Forms)

To detect a mouse click on empty cells add the mouseClick event.

private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
            DataGridView.HitTestInfo ht = dataGridView1.HitTest(e.X, e.Y);
            if (ht != null)
            {
		  //e.RowIndex and e.ColumnIndex can be used.
	     }
}       
Lastest update in September 2017, inital post in September 2017

Write a comment

I appreciate comments, suggestions, compliments etc. Unfortunately I have no time to reply to them. Useful input will be used for sure!