Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How To Fit The RowHeight and ColWidth to the width and height of the text in StringGrid

1,058 views
Skip to first unread message

Irfan Mulic

unread,
Aug 22, 2001, 6:19:56 AM8/22/01
to
I have a problem,
I made a searching engine for the textFiles, and I need to fill the
paragrafs of found text in StringGrid so I need to solve that text need to
be MultiLine (word wrap)???

Can anybody sove this?
Thanks.


Peter Below (TeamB)

unread,
Aug 22, 2001, 2:06:26 PM8/22/01
to
In article <3b8387b1_1@dnews>, Irfan Mulic wrote:
> I made a searching engine for the textFiles, and I need to fill the
> paragrafs of found text in StringGrid so I need to solve that text need to
> be MultiLine (word wrap)???

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.
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.


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.

Irfan Mulic

unread,
Aug 22, 2001, 5:58:18 PM8/22/01
to
Thanks, it realy works!!!


0 new messages