Recent

Author Topic: [Solved] Alter row height in dbgrid without altering the height of titles  (Read 427 times)

Ever

  • New member
  • *
  • Posts: 29
Regards

   As the subject says, I need to alter the height of the rows in a dbgrid without altering the height of the titles. Modifying the DafaultRowHeight property alters the height of both the rows and the titles and I don't want that, I need the height of the titles to remain fixed. For example: high of the rows: 40, high of the titles: 20. That is possible.

Thanks in advance for the support you can provide
« Last Edit: August 01, 2019, 02:29:33 am by Ever »

jamie

  • Hero Member
  • *****
  • Posts: 1735
Re: Alter row height in dbgrid without altering the height of titles
« Reply #1 on: July 28, 2019, 06:47:54 pm »
Try RowHeights [ 0 ]  := SomeIntegerValue;

I don't know if it's exposed in the DBgrid.
Put this at the top of your source in the type section

Code: Pascal  [Select]
  1.  TMyCustomGridHack = Class(TCustomGrid)
  2.    Public
  3.      Property RowHeights;
  4.  end;                        
  5.  

and this is a test button run..
Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   TMyCustomGridHack(DBGrid1).RowHeights[0] := 20;
  4.   DBgrid1.Update;
  5. end;        
  6.  

I tried that with a blank DBGrid and didn't see it change but the grid may need to have something in it..
 The RowsHeights array do change and maintain the height value..

 It's possible I guess the DBGrid could be overriding something but one can never know until we try  :)


 I just noticed you can use the TCustomDrawGrid(DBGrid1).RowHeights[ 0 ] := ?
« Last Edit: July 28, 2019, 10:04:50 pm by jamie »

Ever

  • New member
  • *
  • Posts: 29
Re: Alter row height in dbgrid without altering the height of titles
« Reply #2 on: July 29, 2019, 05:08:32 am »
Thanks for your response
 I used TCustomDrawGrid and achieved what I wanted, I implemented it as follows, I don't know if it's the right one but it worked.

In the type section carry out the following statement, I put part of the code that is before and after so you can get an idea of where to locate it

Code: Pascal  [Select]
  1. type
  2.  
  3.   { Tfsms }
  4.                          
  5.   TMyCustomGrid = Class(TCustomDrawGrid);
  6.   Tfsms = class(TForm)
  7.  
  8.     BCMaterialDesignButton1: TBCMaterialDesignButton;
  9.     BCPanel1: TBCPanel;
  10.     BCPanel2: TBCPanel;
  11.     benviar: TButton;
  12.     blimpiar: TButton;
  13.     DBGrid1: TDBGrid;
  14.     dssms: TDataSource;
  15.     ebcodcli: TEdit;    
  16.  

then in the activate event of the form, I wrote the following

Code: Pascal  [Select]
  1. TMyCustomGrid(DBGrid1).RowHeights[0]:=20;
  2.  

doing it that way, it worked perfectly, but the compiler throws me the following warning...
Class Type "TDBGrid" and "TMyCustomGrid"  are not related

If I implement it badly, I ask you please indicate the correct way to do it.  :-\
Thanks for the support  :)



jamie

  • Hero Member
  • *****
  • Posts: 1735
Re: Alter row height in dbgrid without altering the height of titles
« Reply #3 on: July 29, 2019, 10:51:54 pm »
you don't need to recreate that in your source..

Simply use the TCustomDrawGrid(DBGrid1)./….

you don't need to declare any types in your source, these types already exists...

devEric69

  • Full Member
  • ***
  • Posts: 107
Re: Alter row height in dbgrid without altering the height of titles
« Reply #4 on: July 30, 2019, 11:12:18 am »
A little tip for the RowHeights number 0 for titles, to assign it taking into account the letters:

Code: Pascal  [Select]
  1. RowHeights[0]:= (Canvas.TextHeight('Ŵg') + 4) * iMaxNumberOfLinesInTitles;
« Last Edit: July 30, 2019, 11:19:02 am by devEric69 »
use: Ubuntu 18.04 + Laz. 1.8.5 + FPC 3.0.5 (64 bits).

Ever

  • New member
  • *
  • Posts: 29
Alter row height in dbgrid without altering the height of titles
« Reply #5 on: August 01, 2019, 02:28:17 am »
Jamie thanks for the support provided, I deleted the statement and only implemented the TCustomDrawGrid line (DBGrid1) ./…. It is working very well.

devEric69 thanks for the tip, I will take it into account.

regards   :)
« Last Edit: August 01, 2019, 02:30:26 am by Ever »