You might find this tip useful. Google on 'tstringgrid align' gives many more examples.
JoetjeF
Junior Poster in Training
67 posts since Jun 2005
Reputation Points: 15
Solved Threads: 3
Does anyone know of a good site or doc that describes the ways to use a TStringGrid? I'm trying to figure out how to right-justify some of the items that are going to be placed into a TStringGrid
You'll need write some code on StringGrid's OnDrawCell event.
Just a sample, to write right aligned text on the second column:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer; Rect: TRect; State: TGridDrawState);
var
X, C, R :Integer;
begin
C := Col; R := Row; // it believes is necessary, if use "with" below
if (Col = 2) and (Row > 0) then
with Sender as TStringGrid do
begin
X := Rect.Left +(Rect.Right -Rect.Left) -Canvas.TextWidth(Cells[C, R]) -3;
Canvas.TextRect(Rect, X, Rect.Top +2, Cells[C, R]);
end;
end;
- basically you need calc the start x pos of the text on rect to be paint, using text and rect width;
- Col=0 and Row=0 are fixed column and row. Maybe you can changeRow > 0 by Row >= (Sender as TStringGrid).FixedRows
bye
Micheus
Junior Poster in Training
72 posts since Jun 2006
Reputation Points: 10
Solved Threads: 4
Micheus
Junior Poster in Training
72 posts since Jun 2006
Reputation Points: 10
Solved Threads: 4