How to determine user has clicked DataGridView but not a Cell
c#, datagridview, mouseclick-event, winforms
Solution
You can use `MouseClick` event and do a hit test for it.
private void dgv_MouseClick(object sender, MouseEventArgs e)
{
var ht = dgv.HitTest(e.X, e.Y);
if (ht.Type == DataGridViewHitTestType.None)
{
//clicked on grey area
}
}
Problem
I want to prompt the user to enter new elements into a databound collection when they click in the empty area of a `DataGridView`. How can I find out if the user has clicked inside of the `DataGridView` (the grey area by default), but not in a `Column`/`Row`/`Cell`?