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:
- CustomGrid.cs (VB: CustomGrid.vb)
- Form1.cs (VB: Form1.vb)
(you will be redirected to DevExpress.com to submit your response)