Recent

Author Topic: [Solved] Stringgrid fixed row wordwrap  (Read 6345 times)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
[Solved] Stringgrid fixed row wordwrap
« on: August 31, 2014, 10:00:40 pm »
I am looking for a way to wrap text in the header row of a string grid, so that translations of the header can be accepted without changing the column width.

Changing the header row height works with
Code: [Select]
  StringGrid1.RowHeights[0] := stringgrid1.RowHeights[0] * 2;

This old topic http://forum.lazarus.freepascal.org/index.php/topic,5784.msg27094.html#msg27094 recommends a solution, but using it generates an error: 'Argument can't be assigned to'.

Presumably this worked at the time. Does anyone have any suggestions?

I am using Laz 1.2.4 with FPC 2.6.4, on i7 processor and Linux Mint 16.
 
« Last Edit: September 01, 2014, 01:35:03 pm by Windsurfer »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Stringgrid fixed row wordwrap
« Reply #1 on: August 31, 2014, 10:20:11 pm »
How about:
Code: [Select]
var
  aTextStyle: TTextStyle;
begin
  aTextStyle := TStringGrid(Sender).Canvas.TextStyle;

  aTextStyle.SingleLine := false;
  aTextStyle.Wordbreak := true;

  TStringGrid(Sender).Canvas.TextStyle := aTextStyle;
end;


Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Stringgrid fixed row wordwrap
« Reply #2 on: September 01, 2014, 12:18:56 am »
Thanks Engkin,

I had completely forgotten about changing styles in that way.

I changed the last line to:
Code: [Select]
  if aRow = 0 then
    TStringGrid(Sender).Canvas.TextStyle := aTextStyle;

It compiles and runs. I'll test it tomorrow.

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Stringgrid fixed row wordwrap
« Reply #3 on: September 01, 2014, 01:33:45 pm »
It worked when I moved the code to the OnPrepareCanvas event.

Code: [Select]
procedure TfrmDataView.StringGrid1PrepareCanvas(sender: TObject;
  aCol, aRow: Integer; aState: TGridDrawState);
  var
  aTextStyle: TTextStyle;
begin
  aTextStyle := TStringGrid(Sender).Canvas.TextStyle;
  aTextStyle.SingleLine := False;
  aTextStyle.Wordbreak := True;
  if aRow = 0 then TStringGrid(Sender).Canvas.TextStyle := aTextStyle;
end;
« Last Edit: September 01, 2014, 03:25:35 pm by Windsurfer »

 

TinyPortal © 2005-2018