I am trying to imitate how Windows Explorer handles multiple selections. In the default DataGridView, you can select multiple items using Ctrl-click. But if you release the Ctrl key and then try to drag / drop the selected items, it will clear the selected items and select only the "hit" line. I found the following solution somewhere on the Internet.
protected override OnMouseDown(MouseEventArgs e) { int hitRowIndex = HitTest(eX, eY).RowIndex; if(!SelectedRows.Contains(Rows[hitRowIndex])) { base.OnMouseDown(); } }
However, this causes other side effects. When the CTRL key is pressed and wiped on the selected item, the item remains selected. This makes sense because the mousedown event is thrown out if a row click is selected. Studying the behavior of Windows Explorer, it seems that deselecting an item with the CTRL key is not processed until the MouseUp event. Has anyone tried to do this?
source share