View Issue Details

IDProjectCategoryView StatusLast Update
0027437LazarusLCLpublic2015-09-28 22:53
ReporterwpAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.5 (SVN)Product Build 
Target Version1.4.4Fixed in Version1.5 (SVN) 
Summary0027437: Public method "ClearSelections" for TCustomGrid
DescriptionSometimes 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 ReproduceSee 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 InformationThere 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?
TagsNo tags attached.
Fixed in Revision49885
LazTarget1.6
WidgetsetWin32/Win64
Attached Files
  • grids.pas.patch (1,234 bytes)
    Index: lcl/grids.pas
    ===================================================================
    --- lcl/grids.pas	(revision 47672)
    +++ lcl/grids.pas	(working copy)
    @@ -881,7 +881,6 @@
         procedure CellClick(const aCol,aRow: Integer; const Button:TMouseButton); virtual;
         procedure CheckLimits(var aCol,aRow: Integer);
         procedure CheckLimitsWithError(const aCol, aRow: Integer);
    -    procedure ClearSelections;
         procedure CMBiDiModeChanged(var Message: TLMessage); message CM_BIDIMODECHANGED;
         procedure CMMouseEnter(var Message: TLMessage); message CM_MOUSEENTER;
         procedure CMMouseLeave(var Message :TLMessage); message CM_MouseLeave;
    @@ -1175,6 +1174,7 @@
         function  CellToGridZone(aCol,aRow: Integer): TGridZone;
         procedure CheckPosition;
         procedure Clear;
    +    procedure ClearSelections;
     
         function  EditorByStyle(Style: TColumnButtonStyle): TWinControl; virtual;
         procedure EditorKeyDown(Sender: TObject; var Key:Word; Shift:TShiftState);
    @@ -7422,6 +7422,9 @@
     procedure TCustomGrid.ClearSelections;
     begin
       SetLength(FSelections, 0);
    +  UpdateSelectionRange;
    +  FPivot := Point(Col, Row);
    +  InvalidateGrid;
     end;
     
     procedure TCustomGrid.CMBiDiModeChanged(var Message: TLMessage);
    
    grids.pas.patch (1,234 bytes)
  • grid_clearselections.zip (2,131 bytes)

Relationships

related to 0027745 assignedJesus Reyes TCustomGrid.SelectedRangeCount is not updated after rows clear 

Activities

wp

2015-02-10 13:46

developer  

grids.pas.patch (1,234 bytes)
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 47672)
+++ lcl/grids.pas	(working copy)
@@ -881,7 +881,6 @@
     procedure CellClick(const aCol,aRow: Integer; const Button:TMouseButton); virtual;
     procedure CheckLimits(var aCol,aRow: Integer);
     procedure CheckLimitsWithError(const aCol, aRow: Integer);
-    procedure ClearSelections;
     procedure CMBiDiModeChanged(var Message: TLMessage); message CM_BIDIMODECHANGED;
     procedure CMMouseEnter(var Message: TLMessage); message CM_MOUSEENTER;
     procedure CMMouseLeave(var Message :TLMessage); message CM_MouseLeave;
@@ -1175,6 +1174,7 @@
     function  CellToGridZone(aCol,aRow: Integer): TGridZone;
     procedure CheckPosition;
     procedure Clear;
+    procedure ClearSelections;
 
     function  EditorByStyle(Style: TColumnButtonStyle): TWinControl; virtual;
     procedure EditorKeyDown(Sender: TObject; var Key:Word; Shift:TShiftState);
@@ -7422,6 +7422,9 @@
 procedure TCustomGrid.ClearSelections;
 begin
   SetLength(FSelections, 0);
+  UpdateSelectionRange;
+  FPivot := Point(Col, Row);
+  InvalidateGrid;
 end;
 
 procedure TCustomGrid.CMBiDiModeChanged(var Message: TLMessage);
grids.pas.patch (1,234 bytes)

wp

2015-02-10 13:46

developer  

grid_clearselections.zip (2,131 bytes)

wp

2015-09-28 11:05

developer   ~0086115

There's another user complaining about this bug (http://forum.lazarus.freepascal.org/index.php/topic,26955.msg188769.html#msg188769).

Any chance that this patch will be applied soon? 7 months is quite some time...

Bart Broersma

2015-09-28 15:25

developer   ~0086126

You could send a reminder to Jesus. For developers (Mantis status) it is here:
View Issue Details [ Jump to Notes ] [ Send a reminder ]

wp

2015-09-28 15:58

developer   ~0086128

Reminder sent to: Jesus Reyes

Jesus, could you have a look at this 7-month-old patch? Thanks.

Jesus Reyes

2015-09-28 19:52

developer   ~0086134

Sorry, Applied. Please check if it's eligible for merging.

wp

2015-09-28 22:53

developer   ~0086142

No problem. The patch looks ok for merging to 1.4.4.

Issue History

Date Modified Username Field Change
2015-02-10 13:46 wp New Issue
2015-02-10 13:46 wp File Added: grids.pas.patch
2015-02-10 13:46 wp File Added: grid_clearselections.zip
2015-02-10 13:47 wp Additional Information Updated View Revisions
2015-02-10 13:48 wp Steps to Reproduce Updated View Revisions
2015-03-29 00:12 wp Relationship added related to 0027745
2015-04-01 19:39 Jesus Reyes Assigned To => Jesus Reyes
2015-04-01 19:39 Jesus Reyes Status new => assigned
2015-09-28 11:05 wp Note Added: 0086115
2015-09-28 15:25 Bart Broersma Note Added: 0086126
2015-09-28 15:58 wp Note Added: 0086128
2015-09-28 19:52 Jesus Reyes Fixed in Revision => 49885
2015-09-28 19:52 Jesus Reyes LazTarget - => 1.6
2015-09-28 19:52 Jesus Reyes Note Added: 0086134
2015-09-28 19:52 Jesus Reyes Status assigned => resolved
2015-09-28 19:52 Jesus Reyes Fixed in Version => 1.5 (SVN)
2015-09-28 19:52 Jesus Reyes Resolution open => fixed
2015-09-28 19:52 Jesus Reyes Target Version => 1.6
2015-09-28 22:53 wp Note Added: 0086142
2015-09-28 22:53 wp Status resolved => closed
2015-09-28 22:53 wp Target Version 1.6 => 1.4.4