Setting StringGrid.Height

Posted by Lee Hallin p12462 on January 27, 2009

Hi all,
I have a StringGrid that I populate on the fly. Once I'm done populating it, I want to set the .height property such that the bottom border is just below the [possible horizontal scroll bar and] last line in the StringGrid. When I click the button with the following code, the bottom border ends up below row 7 out of 10 rows. I'm guessing it is because I am summing the height of the characters but not the space above and below the horizontal lines. Is there some other property(s) I should be summing to get the results I want?

procedure TForm1.Button3Click(Sender: TObject);
Var
i,H: Integer;
Begin
H := 0;
For i := 0 to (StringGrid1.RowCount - 1) do Begin
H := H + StringGrid1.Canvas.TextHeight(StringGrid1.Cells[0,i]);
End;
StringGrid1.Height := H;
End; { Button3Click }

Thanks..Lee

Related articles

       

Follow Ups