automatically Change size row of Stringgrid!

Hello everybody!
When i write text in the row Stringgrid,how can i do to automatically change the size row of stringgrid,if this text is so long.
Thanks u!
ongchu001Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel PASQUIERFreelance Project ManagerCommented:
you use the ColWidths property

for example, to resize a column so that it fits the maximum size of all values in the rows :
procedure AutoFitStringGridColumn(SG:TStringGrid;aCol:Integer);
Var
 i,W,MaxW:Integer;
begin
 MaxW:=0;
 With SG do for i:=0 to RowCount-1 do
  begin
   W:=Canvas.TextWidth(Cells[aCol,i]);
   if W>MaxW Then MaxW:=W;
  end;
 SG.ColWidths[aCol]:=MaxW+4; // add 4 pixels to max width
end;

Open in new window

Emmanuel PASQUIERFreelance Project ManagerCommented:
You call such a procedure only once after you add a lot of data.
to avoid doing that (scan all text size for each row) each time you add or change a cell value, you can use a simpler procedure :
procedure AutoFitStringGridCell(SG:TStringGrid;aCol,aRow:Integer);
Var
 W:Integer;
begin
 With SG do 
  begin
   W:=Canvas.TextWidth(Cells[aCol,aRow])+4;
   if W>ColWidths[aCol] Then ColWidths[aCol]:=W;
  end;
end;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Emmanuel PASQUIERFreelance Project ManagerCommented:
ah, and your last 2 question have nothing to do with internet programming, nor Database. Instead, use Delphi Programming zone (you can keep components), this will give opportunity to more experts to correctly answer your question
ongchu001Author Commented:
This is what I need.thanks  epasquier very much  for the help!nice day to u!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.