Cita:
Empezado por mapashhe
Ok amigo, la he leido, muchas gracias.. ahora alguna ayudita?
|
Hola mapashhe.
A ver... probá de este modo:
Código Delphi
[-]
procedure SetGridColumnWidths(aDBGrid: TDBgrid);
const
DEFBORDER = 10;
var
temp, n: Integer;
lmax: array [0..30] of Integer;
begin
with aDBGrid do
begin
DataSource.DataSet.DisableControls;
try
Canvas.Font := Font;
for n := 0 to Columns.Count - 1 do
lmax[n] := Canvas.TextWidth(Fields[n].FieldName) + DEFBORDER;
DataSource.DataSet.First;
while not DataSource.DataSet.EOF do
begin
for n := 0 to Columns.Count - 1 do
begin
temp := Canvas.TextWidth(trim(Columns[n].Field.DisplayText)) + DEFBORDER;
if temp > lmax[n] then lmax[n] := temp;
end;
DataSource.DataSet.Next;
end;
DataSource.DataSet.First;
for n := 0 to Columns.Count - 1 do
if lmax[n] > 0 then
Columns[n].Width := lmax[n];
finally
DataSource.DataSet.EnableControls;
end;
end;
end;
Y tiene razón
Casimiro:
Hay que usar más la búsqueda.
Estoy seguro de haber puesto este código en otra oportunidad y si mal no recuerdo el amigo
Chris puso en el mismo hilo uno no tan exácto pero si mucho mas rápido.
Saludos.
Edito: Y como buscando, al final se encuentra... aquí el enlace: [
Tamaño de fuente en píxeles ]