GARANTIR DESCONTO

Fórum Ajustar coluna do grid #291162

09/08/2005

0

Pessoal existe algum agoritmo pronto, que tb naum deixe lento, tipo:
na hora que eu abrir minha tabela, cada coluna do meu dbgrid tenha seu width ajustado de acordo com a maior tamanho para esse field na tabela ?

exemplo a coluna 1 tem um width de 70

dai minha tabela tem os valores dessa field

reg 1 - 10 caracteres
reg 2 - 15 caracteres
reg 3 - 12 caracteres

gostaria que essa coluna do grid ficasse ajusta de acordo com o
segundo registro.


desde já agradeço.


Alexandre_sbo

Alexandre_sbo

Responder

Posts

09/08/2005

Alexandre_sbo

Pessoal fiz esse codigo de teste porém naum é
ainda o que quero pois tem que navegar por todos os registro
porém creio que naum exista outro modo.

TTeste = record
    Fieldname: string;
    Width: Integer;
  end;

    teste: array of TTeste;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  i: Integer;
begin
  if Length(teste) = 0 then
    begin

      for i := 0 to pred(IBOQuery1.Fields.Count) do
        begin
          SetLength(teste, length(teste) + 1);
          teste[High(teste)].Fieldname := IBOQuery1.Fields[i].FieldName;
          teste[High(teste)].Width := 0;
        end; { <-- For }
    end;

  for i := low(teste) to High(teste) do
    begin
      if Column.FieldName = teste[i].Fieldname then
        begin
          if teste[i].Width < Canvas.TextWidth(Column.Field.AsString) then
            begin
              teste[i].Width := Canvas.TextWidth(Column.Field.AsString);
              Column.Width := teste[i].Width + 10;
            end;
        end; { <-- if }
    end; { <-- For }
end;



Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar