DataGridView使用MouseMove事件实现移动鼠标选中

int VerticalSelectIndex = 0;
		private void UcTxtAss_MouseMove(object sender, MouseEventArgs e)
		{
			if (Math.Abs(e.Location.Y - VerticalSelectIndex) < 2) return;//防止鼠标停留在两行之间时闪烁
			int index = e.Location.Y / itemHeight+ this.dgv.FirstDisplayedScrollingRowIndex;
			if (index>0&&index < dgv.Rows.Count && dgv.Rows[index].Selected == false)
			{
				VerticalSelectIndex = index;
				dgv.Rows[index].Selected =true;
				if (!this.Focused) this.Focus();
			}			
		}

 

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    请登录后查看评论内容