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.
	     }
}       

Leave a Reply

Your email address will not be published. Required fields are marked *