This is the dissasembled code of what happens when you click that cell:
private void OnTopLeftHeaderMouseDown()
{
if (this.MultiSelect)
{
this.SelectAll();
if (-1 != this.ptCurrentCell.X)
{
this.SetCurrentCellAddressCore(this.ptCurrentCell.X, this.ptCurrentCell.Y, false, false, false);
}
}
In order for you to prevent this behavior you have 2 solutions:
- Disable multi selection (if your business logic permits)
Inherit your own datagrid and override OnCellMouseDown
(something like this)
protected override void OnCellMouseDown(DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex == -1 && e.ColumnIndex == -1) return;
base.OnCellMouseDown(e);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…