Dvexpress XtraGrid 如何在行中拖选,选中多行?

[C#代码]

private void SelectRows(GridView view, int startRow, int endRow) {
    if(startRow > -1 && endRow > -1) {
        view.BeginSelection();
        view.ClearSelection();
        view.SelectRange(startRow, endRow);
        view.EndSelection();
    }
}

private int GetRowAt(GridView view, int x, int y) {
    return view.CalcHitInfo(new Point(x, y)).RowHandle;
}

private int StartRowHandle = -1;
private int CurrentRowHandle = -1;


//以下是事件函数,需要根据相应的gridview绑定。

private void gridView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
    StartRowHandle = GetRowAt(sender as GridView, e.X, e.Y);
}

private void gridView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
    int newRowHandle = GetRowAt(sender as GridView, e.X, e.Y);
    if(CurrentRowHandle != newRowHandle) {
        CurrentRowHandle = newRowHandle;
        SelectRows(sender as GridView, StartRowHandle, CurrentRowHandle);
    }
}

private void gridView1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
    StartRowHandle = -1;
    CurrentRowHandle = -1;
}

原文地址:https://www.cnblogs.com/shaoming01/p/dragandslelectmuiltirows.html