diff --git a/components/fpspreadsheet/examples/visual/fpsctrls/main.lfm b/components/fpspreadsheet/examples/visual/fpsctrls/main.lfm index f71cf2b71..349fe6fe8 100644 --- a/components/fpspreadsheet/examples/visual/fpsctrls/main.lfm +++ b/components/fpspreadsheet/examples/visual/fpsctrls/main.lfm @@ -42,7 +42,7 @@ object MainForm: TMainForm Font.Height = -13 Font.Name = 'Arial' MouseWheelOption = mwGrid - Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goThumbTracking, goDblClickAutoSize, goSmoothScroll, goHeaderHotTracking, goCellHints] + Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goThumbTracking, goDblClickAutoSize, goHeaderHotTracking, goCellHints] ParentFont = False RowCount = 101 TabOrder = 1 diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index edb0aa4b8..7a5b1b80c 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -5907,6 +5907,8 @@ begin end; procedure TsCustomWorksheetGrid.SetZoomFactor(AValue: Double); +var + c,r: Integer; begin if (AValue <> GetZoomFactor) and Assigned(Worksheet) then begin inc(FZoomLock); @@ -5916,7 +5918,23 @@ begin UpdateColWidths; UpdateRowHeights; dec(FZoomLock); - Invalidate; + + // Bring active cell back into the viewport: There is a ScrollToCell but + // this method is private. It is called by SetCol/SetRow, though. + if ((Col < GCache.Visiblegrid.Left) or (Col >= GCache.VisibleGrid.Right)) and + (GCache.VisibleGrid.Left <> GCache.VisibleGrid.Right) then + begin + c := Col; + Col := c-1; // "Col" must change in order to call ScrtollToCell + Col := c; + end; + if ((Row < GCache.VisibleGrid.Top) or (Row >= GCache.VisibleGrid.Bottom)) and + (GCache.VisibleGrid.Top <> GCache.VisibleGrid.Bottom) then + begin + r := Row; + Row := r-1; + Row := r; + end; end; end;