Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stringgrid auto column-size 2

Status
Not open for further replies.

paubri

Programmer
Apr 25, 2005
21
ZA
Hi All.

Does anyone know of a way to make stringgrid columns automatically re-size to the length of the longest string in the column. (like when you double click on the line between columns in excel).

Thanks,
British
 
Yep. Something like this.
Be aware of error in the example, this was taken right from the head... ;-)


You have to bundle this loop into a loop for every existing colmn...
Code:
  n := 0;
  for i := 0 to StringGrid1.RowCount -1 do
  begin
    if StringGrid1.Canvas.TextWidth(Stringrid1.Cells[0, i]) > n then
      n := StringGrid1.Canvas.TextWidth(Stringrid1.Cells[0, i])
  end;
  StringGrid1.ColWidths[0] := n

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is always another way to solve it, but I prefer my way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top