Board index » delphi » StringGrid and Memo Content

StringGrid and Memo Content

Hi, there.
    I am trying to find a way to have one or two cells of a stringgrid
display multiple line of text.  With Ctrl-Break, you can get multiple
lines of text in its inplace editor.  However, when you leave the
editing cell, the display changes to single line with || deliminators.
Anyway I can keep the multiple line display when the cell is not in
editing mode?  Or I have to derive a TCustomGrid myself?

James

 

Re:StringGrid and Memo Content


Quote
>     I am trying to find a way to have one or two cells of a stringgrid
> display multiple line of text.  With Ctrl-Break, you can get multiple
> lines of text in its inplace editor.  However, when you leave the
> editing cell, the display changes to single line with || deliminators.
> Anyway I can keep the multiple line display when the cell is not in
> editing mode?  Or I have to derive a TCustomGrid myself?

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)
    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.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Other Threads