-
//用于记录,鼠标是否已按下
-
bool isMouseDown = false;
-
//用于鼠标拖动多选,标记是否记录开始行
-
bool isSetStartRow = false;
-
//用于鼠标拖动多选,记录开始行
-
private int StartRowHandle = -1;
-
//用于鼠标拖动多选,记录现在行
-
private int CurrentRowHandle = -1;
-
//用于实现鼠标拖动选择多行功能中的一个方法,对单元格区域进行选中
-
private void SelectRows(int startRow, int endRow)
-
{
-
if (startRow > -1 && endRow > -1)
-
{
-
gridView.BeginSelection();
-
gridView.ClearSelection();
-
gridView.SelectRange(startRow, endRow);
-
gridView.EndSelection();
-
}
-
}
-
//实现鼠标拖动选择多行 ,鼠标按下事件
-
private void gridView_MouseDown(object sender, MouseEventArgs e)
-
{
-
if (e.Button == MouseButtons.Left)
-
{
-
isMouseDown = true;
-
}
-
}
-
//实现鼠标拖动选择多行 ,鼠标移动时
-
private void gridView_MouseMove(object sender, MouseEventArgs e)
-
{
-
if (isMouseDown)
-
{
-
GridHitInfo info = gridView.CalcHitInfo(e.X, e.Y);
-
//如果鼠标落在单元格里
-
if (info.InRow)
-
{
-
if (!isSetStartRow)
-
{
-
StartRowHandle = info.RowHandle;
-
isSetStartRow = true;
-
}
-
else
-
{
-
//获得当前的单元格
-
int newRowHandle = info.RowHandle;
-
if (CurrentRowHandle != newRowHandle)
-
{
-
CurrentRowHandle = newRowHandle;
-
//选定 区域 单元格
-
SelectRows( StartRowHandle, CurrentRowHandle);
-
}
-
}
-
}
-
}
-
}
-
//实现鼠标拖动选择多行 ,鼠标放开时
-
private void gridView_MouseUp(object sender, MouseEventArgs e)
-
{
-
StartRowHandle = -1;
-
CurrentRowHandle = -1;
-
isMouseDown = false;
-
isSetStartRow = false;
-
}
gridview拖动实现多选
最新推荐文章于 2022-03-29 17:34:54 发布