Selections and ActivePosition

Jul 26, 2009 at 5:30 PM
Edited Jul 26, 2009 at 5:32 PM

Hello,

 I’ve been using M$ DataGridView for a while.  It suffers from quite a few problems with data binding, and also has certain behaviour which I dislike but and which is difficult or impossible to change.

Yet another bug with the data binding the other week inspired me to google for a replacement and fortunately I came across the SourceGrid. Wow! Given that it is free, it’s an impressive piece of work.  Overall, it works very well, is pretty powerful and easy to customize.  Well done to all involved in the project.

There is one aspect of the grid’s behaviour that I am thinking about modifying.  With GridSelectionMode.Row set and EnableMultiSelection true, if you click on a cell (that is not selected) the row gets selected, but then clicking on the same cell the row is not deselected.  However, clicking on another cell in the same row removes the row from the selection.

Looking at the code in MouseSelection.OnMouseDown, this behaviour appears to be “by design”. The relevant lines are:

//If the cell is already selected and the user has the ctrl key pressed then deselect the cell
if (controlPress && grid.Selection.IsSelectedCell(sender.Position) && grid.Selection.ActivePosition != sender.Position)
    grid.Selection.SelectCell(sender.Position, false);
else
    grid.Selection.Focus(sender.Position, !mantainSelection);
 

This prevents removing the active cell from the selection.  I would like to be able to do this, and was just wondering if it is safe for the grid to have an active cell that is not part of a selection or for that matter have selected cells with no cell set as active in the grid.

I’ve not had the chance to dig deep in the source code to see if this would be OK and so would appreciate your feedback.

Thanks

Clarry.

//If the cell is already selected and the user has the ctrl key pressed then deselect the cell
                if (controlPress && grid.Selection.IsSelectedCell(sender.Position) && grid.Selection.ActivePosition != sender.Position)
                    grid.Selection.SelectCell(sender.Position, false);
                else
                    grid.Selection.Focus(sender.Position, !mantainSelection);