DataGridView multiple selection behavior (prior to a drag and drop)

vblm

New member
Joined
Jan 19, 2010
Messages
4
Programming Experience
10+
In windows applications, one usually select desired items by left clicking them with the mouse while pressing the shift or control key, and then doing a final left click on any one of the selected itmes to perform a drag and drop.

However, in a DataGridView (in row selection mode and multiple rows selection enabled), whenever I perform such a last click for a drag and drop over one of the selected rows, all the previously selected rows are deselected and only the row over which I performed the last click is selected. How can I change this behavior ? I use DataGridView_MouseClick and DataGridView_MouseMove to initiate the drag and drop (to a second DGV).

Also, I would like to disable selection of additional rows in the DataGridView while the left mouse button is down (i.e. forcing a click, shift-click or ctrl-click for selecting rows).

As an example of the above, first, try this:
In a DGV, click over a row of your choice (without pressing any key) and while keeping the left mouse button down, move the mouse over other rows of the DGV. You will see that the selection is automatically extended to the adjacent rows over which the mouse moves. I don't mind that behavior when selecting rows but when I start the drag and drop, I don't want that !

Second, try this:
In a DGV, select multiple rows of your choice (possibly not adjacent ones) by clicking over them while pressing the Ctrl key. When all the desired rows are selected and the Ctrl key is released, click on any one of the previously selected rows while keeping the left mouse button down. You will see that as soon as you click on that row, the previous selection is lost and only the clicked row is selected (even if it was already selected in the previous selection). I don't want that ! I want the previous selection of multiple rows to remain (for the drag and drop) as long as the left mouse button is not released. If it is released while inside the DGV, then the drag and drop is cancelled and the selection is reset. Otherwise, the drag and drop of the selected rows is carried out.

Your suggestions would be most welcome as this DataGridView selection behavior problem is bugging me for a long time now and I am clueless. Thanks.
 
Back
Top