View Issue Details

IDProjectCategoryView StatusLast Update
0025835LazarusLCLpublic2014-03-10 11:02
ReporterwpAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86OSWin32OS VersionWin7
Product Version1.3 (SVN)Product Build 
Target Version1.4Fixed in Version1.3 (SVN) 
Summary0025835: StringGrids Selection Issues
DescriptionIn a StringGrid, having the options goRangeSelect and goSelectionActive set, a rectangular range of cells can be selected; the selection can be extended by holding the SHIFT key down when the other corner of the selection rectangle is clicked, or when an arrow key is pressed.

This behavior is broken when the Selection is set by code:
   StringGrid1.Selection := TGridRect(Rect(1,1,2,2));

When now the user tries to extend the selection the 1st corner of the selection is forgotten and a new selection is defined starting at the 2nd corner.

Looking into the source code of procedure TCustomGrid.SetSelection, there is a line resetting the internal variable FSelectActive at the end of the method; therefore, the grid "forgets" that it is in selection mode. In my opinion, FSelectActive is should remain at true.

The attached patch removes this line from SetSelection. Now the Selection behavior of the grid is as expected, and I do not see any side effects.
Steps To ReproduceRun attached program, a rectange between cells (1,1) and (2,2) is selected. Hold the SHIFT key down and click on one of the non-selected cells. The expected behavior is that the selection rectange would extend between cell (1,1) and the clicked cell. The observed behavior is that the selection range extends between cell (2,2) and the selected cell. Therefore, the original selection is "forgotten".
TagsNo tags attached.
Fixed in Revision44389
LazTarget1.4
WidgetsetWin32/Win64
Attached Files
  • StringGrid_Selection.zip (2,065 bytes)
  • grids.pas.patch (380 bytes)
    Index: grids.pas
    ===================================================================
    --- grids.pas	(revision 44226)
    +++ grids.pas	(working copy)
    @@ -5241,7 +5241,6 @@
             FPivot := FRange.TopLeft;
             FSelectActive := True;
             MoveExtend(false, FRange.Right, FRange.Bottom);
    -        FSelectActive := OldSelectActive;
           end;
           Invalidate;
         end;
    
    grids.pas.patch (380 bytes)

Activities

wp

2014-03-08 12:32

developer  

StringGrid_Selection.zip (2,065 bytes)

wp

2014-03-08 12:33

developer  

grids.pas.patch (380 bytes)
Index: grids.pas
===================================================================
--- grids.pas	(revision 44226)
+++ grids.pas	(working copy)
@@ -5241,7 +5241,6 @@
         FPivot := FRange.TopLeft;
         FSelectActive := True;
         MoveExtend(false, FRange.Right, FRange.Bottom);
-        FSelectActive := OldSelectActive;
       end;
       Invalidate;
     end;
grids.pas.patch (380 bytes)

Jesus Reyes

2014-03-09 23:17

developer   ~0073575

Applied with changes to remove unnecessary local var, please test.

wp

2014-03-10 11:02

developer   ~0073583

Running fine. Thank you

Issue History

Date Modified Username Field Change
2014-03-08 12:32 wp New Issue
2014-03-08 12:32 wp File Added: StringGrid_Selection.zip
2014-03-08 12:33 wp File Added: grids.pas.patch
2014-03-08 15:25 Zeljan Rikalo Assigned To => Jesus Reyes
2014-03-08 15:25 Zeljan Rikalo Status new => assigned
2014-03-09 23:17 Jesus Reyes Fixed in Revision => 44389
2014-03-09 23:17 Jesus Reyes LazTarget => 1.4
2014-03-09 23:17 Jesus Reyes Note Added: 0073575
2014-03-09 23:17 Jesus Reyes Status assigned => resolved
2014-03-09 23:17 Jesus Reyes Fixed in Version => 1.3 (SVN)
2014-03-09 23:17 Jesus Reyes Resolution open => fixed
2014-03-09 23:17 Jesus Reyes Target Version => 1.4
2014-03-10 11:02 wp Note Added: 0073583
2014-03-10 11:02 wp Status resolved => closed