Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

Stringgrid - multiline text

306 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Nermi Karacabeyli

ungelesen,
21.07.2001, 13:48:1221.07.01
an
Is there any easy way to display a multiline or wrapped text in a particular
cell in the stringrid?
Thanks,
Nermi


Nermi Karacabeyli

ungelesen,
21.07.2001, 13:51:1521.07.01
an

Peter Below (TeamB)

ungelesen,
22.07.2001, 10:38:3122.07.01
an
In article <3b59886e_2@dnews>, Nermi Karacabeyli wrote:
> Is there any easy way to display a multiline or wrapped text in a particular
> cell in the stringrid?

You can do it using an OnDrawCell handler and the DrawText API function.

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.
The main problem is that it will not automatically *decrease* the row height
if the text would fit into a smaller row. It cannot do that since there may be
other cells in the row that need a taller row. You could fix that problem by
setting the rowheigh back to the defaultrowheight when you change the cell
data for a row, that would trigger a redraw and that in turn would adjust the
rowheight to what is needed. It would cause some flicker, though.

The grids inplace editor is also not up to editing such cells properly, so
there will be problems if the grid needs to be editable.


Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

0 neue Nachrichten