0

I'm programming in Delphi and I want to have a vertical Scrollbar that is always visible, even if the number of rows is 1 (the DefaultDrawing option is not active, i'm using Canvas to draw the cells).

Can anyone help me ?

Thomas Jomphe
  • 117
  • 6
  • 17
  • 1
    You need to customize the control. Or use a different control – David Heffernan May 09 '16 at 20:38
  • Just of curiosity, may I ask why? Has it something to do with you yourself drawing the cells? – Tom Brunberg May 10 '16 at 07:29
  • @TomBrunberg it's usually a matter of trying to find the ideal default widths of the columns in a string grid. If you do that taking the width of the scroll bar into account, it looks terrible if there is no scroll bar. (been there, done that) – dummzeuch May 10 '16 at 09:17

1 Answers1

1

You could interpose TStringGrid and override the Resize method, like so:

unit Unit1;

interface

uses
  Winapi.Windows, System.Classes, Vcl.Controls, Vcl.Forms, Vcl.Grids;

type
  TStringGrid = class(Vcl.Grids.TStringGrid)
  protected
    procedure Resize; override;
  end;

  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
  end;

implementation

{$R *.dfm}

{ TStringGrid }

procedure TStringGrid.Resize;
begin
  inherited Resize;
  ShowScrollBar(Handle, SB_VERT, True);
end;

end.

A minor test with anchors set gives good results here.

NGLN
  • 43,011
  • 8
  • 105
  • 200