From: "Peter Below (TeamB)" <100113.1101@compuXXserve.com> Subject: Re: Word wrap in TStringGrid Date: 03 Apr 1999 00:00:00 GMT Message-ID: Content-Transfer-Encoding: 8bit References: <3705452A.26B219A4@iitri.org> Content-Type: text/plain; charset=iso-8859-1 Organization: TeamB Mime-Version: 1.0 Reply-To: 100113.1101@compuXXserve.com Newsgroups: borland.public.delphi.vcl.components.using > Is there a way to have one column of a TStringGrid word wrap? > > I've tried inserting #10#13 into the string, but an unprintable > character appears instead of the newline. > you can do this with a OnDrawCell handler for the grid: procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer; Rect: TRect; State: TGridDrawState); var S: String; drawrect :trect; begin S:= (Sender As TStringgrid).Cells[ Col, Row ]; If Length(S) > 0 Then Begin drawrect := rect; DrawText((Sender As TStringgrid).canvas.handle, Pchar(S), Length(S), drawrect, dt_calcrect or dt_wordbreak or dt_left ); If (drawrect.bottom - drawrect.top) > (Sender As TStringgrid).RowHeights[row] Then (Sender As TStringgrid).RowHeights[row] := (drawrect.bottom - drawrect.top) // changing the row height fires the event again! Else Begin drawrect.Right := rect.right; (Sender As TStringgrid).canvas.fillrect( drawrect ); DrawText((Sender As TStringgrid).canvas.handle, Pchar(S), Length(S), drawrect, dt_wordbreak or dt_left); End; End; end; It will automatically adjust the row height to larger values if needed. Peter Below (TeamB) 100113.1101@compuserve.com) No e-mail responses, please, unless explicitely requested!