Public method "ClearSelections" for TCustomGrid
Original Reporter info from Mantis: wp @wpam
-
Reporter name:
Original Reporter info from Mantis: wp @wpam
- Reporter name:
Description:
Sometimes it is necessary to clear the selected ranges in a grid. There is already a method "ClearSelections", but it is not public.
A public method "ClearSelections", however, needs some refinements because the displayed grid does not change when ClearSelections is called. Moreover, there is some unexpected behavior when SHIFT is held down during the next click after ClearSelections has been called: it is expected to select a range between the newly focused cell and the cell that was focused when ClearSelections was called. But the range extends to the pivot used before ClearSelections.
The required changes to "ClearSelections" are included in the attached patch:
procedure TCustomGrid.ClearSelections;
begin
SetLength(FSelections, 0);
UpdateSelectionRange; // <- added
FPivot := Point(Col, Row); // <- added
InvalidateGrid; // <- added
end;
Steps to reproduce:
See attached demo:
- Using the current grids.pas the demo does not compile because ClearSelections is not public.
- After making ClearSelections public, selecting a range, and clicking "Clear Selections", the selected range does not disappear.
- After application of the patch, the grid behaves as expected.
Additional information:
There is also an unexpected behavior when the active cell is moved programmatically.
- Add a button with an OnClick handler that sets the grid's "Col := 1; Row := 1".
- Select a range.
- Click on the button.
--> The selection now extends from the pivot of the previously selected range to the newly focused cell.
My expectation would have been that the selected range would disappear, and only the cell 1/1 would be selected.
But maybe this not a bug because it still should be possible to move the active cell programmatically if SelectActive is true.
The next idea was to call ClearSelections in the OnClick handler of the button before moving the focused cell. But this does not work either because ClearSelection resets the pivot to the previously selected cell. Calling ClearSelections after moving the active cell, however, is ok.
But maybe there are better ways to reset the pivot in ClearSelections?
Mantis conversion info:
- Mantis ID: 27437
- Version: 1.5 (SVN)
- Fixed in version: 1.5 (SVN)
- Fixed in revision: 49885 (#40e2ef95)
- Monitored by: » Penilopa P (Anton)
- Target version: 1.4.4
- LazTarget: 1.6