参考代码:
var
I, J, L: Integer;
lCanvas: TCanvas;
begin
lCanvas := TCanvas.Create;
try
lCanvas.Handle := Borland.Delphi.Windows.GetDC(0);
lCanvas.Font := DecisionGrid.DataFont; //TODO:
for I := 0 to DecisionGrid.ColCount - 1 do
begin
if (I = 0) and (TDecisionGridOption.cgOutliner in DecisionGrid.Options) then
Continue;
L := 0;
for J := 0 to DecisionGrid.RowCount - 1 do
L := Math.Max(L, lCanvas.TextWidth(DecisionGrid.Cells[I - DecisionGrid.FixedCols, J - DecisionGrid.FixedRows]));
DecisionGrid.ColWidths[I] := L + 8;
end;
finally
Borland.Delphi.Windows.ReleaseDC(0, lCanvas.Handle);
lCanvas.Free;
end;
end;
这段代码必须在DeicsionGrid数据加载出来以后做才可以,也就是说DecisionGrid连接的数据源打开后,再取执行这断代码 |