美文网首页
C# 判断datagridView 是否点击在空白区域

C# 判断datagridView 是否点击在空白区域

作者: a9b854aded01 | 来源:发表于2017-12-11 14:02 被阅读0次
#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();
            }
        }

相关文章

网友评论

      本文标题:C# 判断datagridView 是否点击在空白区域

      本文链接:https://www.haomeiwen.com/subject/bmqcixtx.html