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

TListView word wrap

460 views
Skip to first unread message

Jamie Geddes

unread,
Jun 8, 2001, 9:34:53 AM6/8/01
to
Hi,

I have a problem with the TListView component - I want to be able to word
wrap the text within a subitem. The listview style is set to vsReport, with
2 columns contained in it. The first column in my list is very short, with
only around 5 or 6 alphanumeric chars. The second column can contain long
strings however, which I want to be able to display on screen all at once.

The TListView component does not appear to have a word wrap property, so any
ideas on how I can fix this problem?

Thanks in advance,
Jamie


Peter Below (TeamB)

unread,
Jun 8, 2001, 4:42:23 PM6/8/01
to

It is not fixable as far as i know, the MS listview common simply does not
support this kind of stuff. You would probably also need the rows to be of
variable height, which it also does not support.

You can do this using a TStringgrid, it requires a handler for the OnDrawCell
event, though.

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.

Werner Cloete

unread,
Jun 11, 2001, 1:55:58 AM6/11/01
to

Hi

Don't know if this is close to what you are looking for but here goes...
;o)

Have you had a look at ListView1.IconOptions.WrapText ?

"Jamie Geddes" <j...@netdevil.nospam.co.uk> wrote in message
news:3b20d484_1@dnews...
: Hi,

:
:


Jamie Geddes

unread,
Jun 11, 2001, 5:10:25 AM6/11/01
to
Peter,

thanks for that, I had actually been using that code,but was hoping that I
could perform the same operation with a listview, as this would have been
much simpler.

Cheers,
Jamie

"Peter Below (TeamB)" <10011...@compuXXserve.com> wrote in message
news:VA.0000721...@antispam.compuserve.com...

Ernest Fairchild

unread,
Jun 11, 2001, 1:53:08 PM6/11/01
to
That only works for iconic view (possibly only Large Icon view). It does not
work with Report view.

Have a great day!

Ernest
(efair...@home.com)
_____________________
"A father is someone who carries pictures where his money used to be."

Visit my website at http://www.public.asu.edu/~ernestf

"Werner Cloete" <WACl...@OldMutual.com> wrote in message
news:3b245d71_2@dnews...

0 new messages