set wwdbgrid widths programmatically
The following is code that I use:
PROCEDURE TfrmCorrCoef.memTblAnddbgFieldDefs;
BEGIN
memTbl.FieldDefs.Add('Blood Chem', ftString, 16, FALSE);
memTbl.FieldDefs.Add('Blood Test', ftString, 32, FALSE);
memTbl.FieldDefs.Add('Comment', ftString, 64, FALSE);
dbg.AddField('Blood Chem', 0, TRUE);
dbg.AddField('Blood Test', 1, TRUE);
dbg.AddField('Comment', 2, TRUE);
dbg.ColumnByName('Blood Chem').DisplayWidth := 16;
dbg.ColumnByName('Blood Test').DisplayWidth := 32;
dbg.ColumnByName('Comment').DisplayWidth := 64;
END;
What I want to do is set the column widths programmatically. What do I need to do to make this work?
-
Hmm... Well, I mentioned ColWidths because that's what I read in the help file: "Set ColWidths at runtime to change the width of an individual column."
But here's a procedure I've called from a form's OnResize even handler which does work:
procedure TMyMainForm.AdjustLastGridColumn(wwGrid: TwwDBGrid);
var
TotalColumnWidth: Integer;
begin
TotalColumnWidth := 0;
for var i := 0 to wwGrid.GetColCount - 2 do begin
TotalColumnWidth := TotalColumnWidth + wwGrid.ColWidthsPixels[i];
end;
wwGrid.ColWidthsPixels[wwGrid.GetColCount - 1] := Width -
TotalColumnWidth - 20 - { "20" for a little extra padding }
GetSystemMetrics(SM_CXVSCROLL) -
GetSystemMetrics(SM_CYBORDER) * 2 -
GetSystemMetrics(SM_CXSIZEFRAME) * 2 -
GetSystemMetrics(SM_CXPADDEDBORDER) * 2;
end;
Please sign in to leave a comment.
Comments
4 comments