Recent

Author Topic: Autosizing rows in TDBGrid  (Read 2311 times)

RedHelix

  • Newbie
  • Posts: 3
Autosizing rows in TDBGrid
« on: September 21, 2016, 01:00:37 pm »
I've got rather long string in from a query and I like it to be seen full in TDBGrid.
So I need:
Part 1) Make cells of certain column multistring
Part 2) Make rows autosizeable (depending on strings count).

For 1) I used PrepareCanvas:

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.gridDetPrepareCanvas(sender: TObject; DataCol: Integer;
  2.   Column: TColumn; AState: TGridDrawState);
  3. var
  4.    ItemsTextStyle: TTextStyle;
  5. begin
  6.   with (sender as TDBGrid) do
  7.   begin
  8.   if (DataCol=2) then begin
  9.       ItemsTextStyle:= Canvas.TextStyle;
  10.       ItemsTextStyle.SingleLine:=false;
  11.       ItemsTextStyle.WordBreak:=true;
  12.       Canvas.TextStyle:=ItemsTextStyle;
  13.    end;
  14.   end;
  15. end;  

Now there is a multistring text in rows with old height for 1-string text.
How should I solve part 2?
« Last Edit: September 21, 2016, 03:58:00 pm by RedHelix »

mig-31

  • Sr. Member
  • ****
  • Posts: 308
Re: Autosizing rows in TDBGrid
« Reply #1 on: September 21, 2016, 03:15:07 pm »
Use DbGrid1.Canvas.GetTextWidth() to text text width.
Lazarus 4.0 - OpenSuse Leap 15.4, Mageia 8, CentOS 7

RedHelix

  • Newbie
  • Posts: 3
Re: Autosizing rows in TDBGrid
« Reply #2 on: September 21, 2016, 03:57:34 pm »
Sorry, I did not quite catch how I should use it.  :-[
This function just returns text width and my problem is row/cell height when I make this text multylined in a cell with narrower width...

 

TinyPortal © 2005-2018