Even I changed the width of each column (field) but the display of grid is not what I want (no adjust the column width). How ?
Please advise.
Thanks.
Even I changed the width of each column (field) but the display of grid is not what I want (no adjust the column width). How ?
Please advise.
Thanks.
I always had to do it manually.
If it helps, below is how I do it.
I'm sure it's not the best way, but that's how I've been running for 4 years+:
The first proc works on existing grid columns, and the second one works on the dataset's visible fields (clearing grid preexisting columns).
All grids with 1 fixedrow and 1 fixedcol.
class procedure TGenTMSVCLUtils.DBAdvGridConfigDataColumns(AGrid: TDBAdvGrid);
var
xCol : TCollectionItem;
xFld : TField;
sDisplayFormat : string;
begin
AGrid.BeginUpdate;
for xCol in AGrid.Columns do begin
xFld := TDBGridColumnItem(xCol).Field;
if Assigned(xFld) then begin
sDisplayFormat := '';
if xFld is TNumericField then
sDisplayFormat := TNumericField(xFld).DisplayFormat
else if xFld is TDateTimeField then
TDBGridColumnItem(xCol).Editor := edDateEdit
;
with TDBGridColumnItem(xCol) do begin
FloatFormat := sDisplayFormat;
Alignment := xFld.Alignment;
HeaderAlignment := xFld.Alignment;
Width := xFld.DisplayWidth;
end;
end;
end;
AGrid.EndUpdate;
// AGrid.AutoSizeColumns(True);
end;
class procedure TGenTMSVCLUtils.DBAdvGridConfigDataColumnsEx(AGrid: TDBAdvGrid);
var
xCol : TDBGridColumnItem;
xFld : TField;
sDisplayFormat : string;
begin
AGrid.BeginUpdate;
AGrid.ColCount := 1;
for xFld in AGrid.DataSource.DataSet.Fields do begin
if not xFld.Visible then Continue;
xCol := AGrid.Columns.Add;
sDisplayFormat := '';
if xFld is TNumericField then
sDisplayFormat := TNumericField(xFld).DisplayFormat
;
with xCol do begin
Field := xFld;
if xFld is TDateTimeField then
xCol.Editor := edDateEdit
else
xCol.Editor := edNormal;
Header := xFld.DisplayLabel;
FloatFormat := sDisplayFormat;
Alignment := xFld.Alignment;
HeaderAlignment := xFld.Alignment;
Width := xFld.DisplayWidth;
end;
end;
AGrid.FixedCols := 1;
AGrid.EndUpdate;
// AGrid.AutoSizeColumns(True);
end;
Any other simple way ? I just adjust the column width that is the basic requirement . how come it is so complicated ? TMS support can answer this question too ? Thanks all.
You could take part of this logic to adjust only the column widths.
What could be simpler than copy/paste a couple of generic procedures source code that would solve your current urgent requirements and besides can do a bit more than what you needed?
It's run only once after assigning a dataset to the grid.