Valeu, senhor(a) CRM. Perfeito, se mover as variaveis Totwidth e Varwidth dentro do for loop! Assim:
procedure TForm1.AjustaColunas(DBGrid: TDBGrid); var i, j: integer; TotWidth : integer; VarWidth : integer; begin Q1.DisableControls; for i := 0 to -1 + DBGrid.Columns.Count do begin TotWidth := 0; VarWidth := 0; Q1.First; for j := 0 to Q1.RecordCount do begin TotWidth := Canvas.TextWidth(DBGrid.Columns[i].Field.Text); if TotWidth > VarWidth then DBGrid.Columns[i].Width := TotWidth + 8; if VarWidth < TotWidth then VarWidth := TotWidth; Q1.Next; end; end; Q1.First; Q1.EnableControls; end; Muuuuuito obrigado! E um grande obrigado e abraco a todos que responderam. Steve -----Original Message----- From: delphi-br@yahoogrupos.com.br [mailto:delphi...@yahoogrupos.com.br]on Behalf Of CRM Desenvolvimentos Sent: 01 December 2009 10:35 To: delphi-br@yahoogrupos.com.br Subject: Re: FW: [delphi-br] Largura de colunas de DBGrid procedure TfrmForm.AjustaColunas(DBGrid: TDBGrid); var i, j: integer; TotWidth : integer; VarWidth : integer; begin TotWidth := 0; VarWidth := 0; dados.TABELA.DisableControls; for i := 0 to -1 + DBGrid.Columns.Count do begin dados.TABELA.First; for j := 0 to dados.TABELA.RecordCount do begin TotWidth := Canvas.TextWidth(DBGrid.Columns[i].Field.Text); if TotWidth > VarWidth then DBGrid.Columns[i].Width := 8 + TotWidth; if VarWidth < TotWidth then VarWidth := TotWidth; dados.TABELA.Next; end; end; dados.TABELA.First; dados.TABELA.EnableControls; end; *************************************************************************** This e-mail and any files transmitted with it are confidential. If you are not the intended recipient, any reading, printing, storage, disclosure, copying or any other action taken in respect of this e-mail is prohibited and may be unlawful. If you are not the intended recipient, please notify the sender immediately by using the reply function and then permanently delete what you have received. Content of emails received by this Trust will be subject to disclosure under the Freedom of Information Act 2000, subject to the specified exemptions, including the Data Protection Act 1998 and Caldicott Guardian principles. This footnote also confirms that, unless otherwise stated, this email message has been swept by Sophos Anti-virus for the presence of computer viruses. ** Please consider the environment before printing this email. ** ***************************************************************************