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