Recent

Author Topic: How can i change width of Fix-Column DBGrid??  (Read 3678 times)

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
How can i change width of Fix-Column DBGrid??
« on: August 09, 2017, 03:06:19 pm »
Hi
.
How can i change width of Fix-Column DBGrid( Red area in image attached)??
.
Thankyou

howardpc

  • Hero Member
  • *****
  • Posts: 3199
Re: How can i change width of Fix-Column DBGrid??
« Reply #1 on: August 09, 2017, 06:31:26 pm »
It is not possible with TDBGrid, since its options lack a flag equivalent to TStringGrid's goFixedColSizing.
Perhaps by creating a descendant control you could make access to sizing the fixed column possible, but its design indicates that this possiblity has been excluded deliberately.

GetMem

  • Hero Member
  • *****
  • Posts: 3515
Re: How can i change width of Fix-Column DBGrid??
« Reply #2 on: August 09, 2017, 07:37:43 pm »
@majid.ebru
You should subclass TDBGrid or write a class helper, but if you're lazy just copy DBGrid.pas from $(LazarusDir)\lcl folder to your project directory and change the line(see screenshot).

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
Re: How can i change width of Fix-Column DBGrid??
« Reply #3 on: August 10, 2017, 08:12:56 pm »
Oh my God

thank you very much  but i think i can not do that, that is Dangerous  :o :o
« Last Edit: August 11, 2017, 11:06:59 am by majid.ebru »

wp

  • Hero Member
  • *****
  • Posts: 6454
Re: How can i change width of Fix-Column DBGrid??
« Reply #4 on: August 10, 2017, 08:31:43 pm »
Open a bugtracker ticket with a feature request. I don't see a reason why this number should be hard-coded. I It could a public property of TDBGrid, or at least a var in the interface section of dbgrids as well. Even scaling of the grid with screen resolution does not work here.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Handoko

  • Hero Member
  • *****
  • Posts: 3231
  • My goal: build my own game engine using Lazarus
Re: How can i change width of Fix-Column DBGrid??
« Reply #5 on: August 10, 2017, 08:35:58 pm »
@majid.ebru

You can use the similar trick here to access the ColWidths:
http://forum.lazarus.freepascal.org/index.php/topic,37851.msg255814.html#msg255814

wp

  • Hero Member
  • *****
  • Posts: 6454
Re: How can i change width of Fix-Column DBGrid??
« Reply #6 on: August 10, 2017, 09:45:56 pm »
I did try this
Code: Pascal  [Select]
  1. type
  2.   TMyDBGrid = class(TDBGrid);
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. begin
  6.   TMyDBGrid(DBGrid1).ColWidths[0] := 50;
  7. end;

But against all expectations it does not work.

Looking at the source code I find the following method which seems to be called whenever a column width changes. This is where the width of the indicator cell is set to 12 pixesl. So, if my hacked button-click code above, tries to set the indicator width to 50, the change of this column triggers UpdateGridColmnSizes which resets it back to 12...

Code: Pascal  [Select]
  1. procedure TCustomDBGrid.UpdateGridColumnSizes;
  2. var
  3.   i: Integer;
  4. begin
  5.   {$ifdef dbgDBGrid}
  6.   DebugLn('%s.UpdateGridColumnSizes', [ClassName]);
  7.   {$endif}
  8.   if FDefaultColWidths then begin
  9.     if dgIndicator in Options then
  10.       ColWidths[0]:=12;
  11.     if NeedAutoSizeColumns then
  12.       UpdateAutoSizeColumns;
  13.   end;
  14. end;
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

majid.ebru

  • Sr. Member
  • ****
  • Posts: 388
Re: How can i change width of Fix-Column DBGrid??
« Reply #7 on: August 11, 2017, 11:06:24 am »
@majid.ebru
You should subclass TDBGrid or write a class helper, but if you're lazy just copy DBGrid.pas from $(LazarusDir)\lcl folder to your project directory and change the line(see screenshot).

Hi
.
this code work.

thankyou