Dbgrid columnwidth

54 views
Skip to first unread message

rudolph.ga...@googlemail.com

unread,
Aug 26, 2020, 1:10:29 AM8/26/20
to Rosi Delphi Components
Hi,
I am using rdbgrid.
for columnwidth I am using cwAutoWidth.
I want to have some of my columns to be on a fixed width, so I added them to FieldsFixedCollumnWidth as Stringlist but still all columns are Auto resized.
Is there anything else I need to setup?
In the stringlist i just write down the column Fieldname line by line is this ok?

Tomas Rosinsky

unread,
Aug 26, 2020, 10:26:56 AM8/26/20
to Rosi Delphi Components
Hello, there is no other setting needed, just place list of FieldName to the FieldsFixedCollumnWidth property and then these fields should keep its current widh.

It is evaluated by  following code, so you can check it it returns TRUE for your columns:

function TrDBGrid.IsFixedColumnWidth(F: TField): boolean;
begin
  Result:=Assigned(F) and (FFieldsFixedColumnWidth.IndexOf(F.FieldName) >= 0);
  DoGeneralEventFieldBool(geIsFixedColumn, F, Result);
end;

If the issue persists please send me your simple demo project and I will check it.
Thanks
Tomas

RuGaDelphi

unread,
Aug 26, 2020, 10:58:50 AM8/26/20
to Rosi Delphi Components
I tested it also with your demo project using the summary and hints form.
When I turn autowidth on in your sample in design time the columns are autoscaled Correct.
at runtime the autowidth does not work at all

Tomas Rosinsky

unread,
Aug 26, 2020, 2:25:55 PM8/26/20
to Rosi Delphi Components
Please open my DBDemo project (e.g. DBDemo_ADO), open form f_rdbgrid1, select Column width tab and add Button with following code:

procedure TrDBGrid1.btDefFixColWidthClick(Sender: TObject);
begin
  gr1.FieldsFixedColumnWidth.Clear;
  gr1.FieldsFixedColumnWidth.Add('EmployeeID');
  gr1.FieldsFixedColumnWidth.Add('PartTime');
  gr1.SetColumnWidth(cwAutoWidth);
end;

You can see that all column widths are updated except 2 columns - EmployeeID + PartTime.
So it works correctly in my opinion.

I hope it helps
Tomas
Reply all
Reply to author
Forward
0 new messages