#region 判断DGV是否点击空白
public int GetRowIndexAt(int mouseLocation_Y)
{
if (this.View.Dgv_storage.FirstDisplayedScrollingRowIndex < 0)
{
return -1;
}
if (this.View.Dgv_storage.ColumnHeadersVisible == true && mouseLocation_Y <= this.View.Dgv_storage.ColumnHeadersHeight)
{
return -1;
}
int index = this.View.Dgv_storage.FirstDisplayedScrollingRowIndex;
int displayedCount = this.View.Dgv_storage.DisplayedRowCount(true);
for (int k = 1; k <= displayedCount;)
{
if (this.View.Dgv_storage.Rows[index].Visible == true)
{
Rectangle rect = this.View.Dgv_storage.GetRowDisplayRectangle(index, true); // 取该区域的显示部分区域
if (rect.Top <= mouseLocation_Y && mouseLocation_Y < rect.Bottom)
{
return index;
}
k++;
}
index++;
}
return -1;
}
#endregion
public void Dgv_storageMouseClick(object sender,MouseEventArgs e)
{
if (GetRowIndexAt(e.Y) == -1)
{
this.View.Dgv_storage.ClearSelection();
}
}
网友评论