Skip to content

Select multiple grid rows by dragging the mouse in RowSelect mode.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/winforms-grid-select-multiple-rows-with-mouse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Data Grid - Select multiple rows by dragging the mouse in RowSelect mode

In GridMultiSelectMode.CellSelect mode, users can select a contiguous block of cells by dragging the mouse over them. To select multiple rows in the same way in GridMultiSelectMode.RowSelect mode, create a GridView descendant and override GridHandler.OnMouseDown and GridHandler.OnMouseMove methods:

protected override bool OnMouseDown(MouseEventArgs ev) {
    var result = base.OnMouseDown(ev);
    if (ev.Button == MouseButtons.Left && Control.ModifierKeys == Keys.None && View.IsRowSelect && DownPointHitInfo.InRowCell)
        mouseDownHitInfo = DownPointHitInfo;
    else
        mouseDownHitInfo = null;
    return result;
}
protected override bool OnMouseMove(MouseEventArgs ev) {
    var result = base.OnMouseMove(ev);
    if (!result && ev.Button == MouseButtons.Left && mouseDownHitInfo != null) {
        var dragSize = SystemInformation.DragSize;
        var dragRect = new Rectangle(
            new Point(mouseDownHitInfo.HitPoint.X - dragSize.Width / 2, mouseDownHitInfo.HitPoint.Y - dragSize.Height / 2),
            dragSize);
        if (!dragRect.Contains(ev.Location)) {
            mouseDownHitInfo = null;
            View.StartAccessSelection();
            result = true;
        }
    }
    return result;
}

Files to look at:

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)