sábado, 26 de fevereiro de 2011

Delphi - Stringrid multilinha

Código para StringGrid multilinha - quebrar o texto em linhas.

Depois, basta adicionar o + #13 entre o texto que você quer quebrar.

procedure TForm1.StringGrid1DrawCell(Sender: TObject;
Col, Row: Longint;
Rect: TRect;
State: TGridDrawState);

var
Line1: string;
Line2: string;
ptr: integer;
padding: integer;
begin

If (ACol > 0) and (ARow >0) Then
Begin
ptr := Pos(';', StringGrid1.Cells[ACol, ARow]);
if ptr > 0 then
begin
Line1 := Copy(StringGrid1.Cells[ACol, ARow], 1, ptr - 1);
Line2 := Copy(StringGrid1.Cells[ACol, ARow], ptr + 1,
Length(StringGrid1.Cells[ACol,ARow]) - ptr);
end
else
Line1 := StringGrid1.Cells[ACol, ARow];

StringGrid1.Canvas.FillRect(Rect);
StringGrid1.Canvas.TextOut(Rect.Left, Rect.Top + 2, Line1);
if ptr > 0 then
StringGrid1.Canvas.TextOut(Rect.Left, Rect.Top -
StringGrid1.Canvas.Font.Height + 3, Line2);

End;