Word wrap in a listbox cell

When displaying data from a database in a listbox, is it possible to display the data with word wrap in the listbox cell? rather than relying on horizontal scrolling?

One way is to leave the Cells empty and store your Cell Texts in the CellTags.
Then paint it in the CellTextPaint event.

Something like this:

g.DrawString(Me.CellTag(row, column), 0, g.TextAscent, g.Width, False)
Me.DefaultRowHeight = g.StringHeight(Me.CellTag(row, column), g.Width) + g.TextAscent / 2

It’s not a clean solution but maybe you can use it.

If the text doesn’t fit into the width, the DrawString solution seems to be a clean solution to me.

Thanks… I’ll give both ideas a try.

Could you provide a code example on setting up the listbox cell with a graphic for the g.drawstring() to populate the cell with text?

I’m looking for something similar to this… which doesn’t work:
where g is graphic, and data1 is a dataset return, and listbox1 has 4 columns
For example, the data field “longtext” can be up to 512 characters so word wrap is needed in the listbox cell for column 3

  While Not data1.EOF
    g1.DrawString("this is it",Listbox1.Celltag(listbox1.lastindex,3),250)

Well, in order to read the text, you need to adjust the height of the row.
In the standard Xojo Listbox, you cannot adjust the height of just a single row.

In your listbox, place this in the CellTextPaint event to see what I mean:

  g.DrawString(Me.Cell(row, column), 0, g.TextAscent, g.Width, False)
  Dim newHeight As Integer = g.StringHeight(Me.Cell(row, column), g.Width) + g.TextAscent / 2
  If Me.RowHeight <> newHeight Then
    Me.DefaultRowHeight = newHeight
  End If
  Return True

That made a major difference. However, the placement of the code may be the issue. That is, after simply dropping that into the CellTextPaint event, and launching the code…

Since I loaded the listbox from a method, the initial display of the data did not reflect the drawstring() event. When I clicked into any cell in the populated listbox, the cells resized as well as did the word wrap.

I will play with the ‘where’ to place it later this evening. This is definitely the right track to follow. Thanks. Always open to learning.

I think Karen’s Mergeable ListBox has WordWrap capabilities. Might be worth the purchase instead of reinventing the wheel.

It does support word wrap. it does NOT simply use g.DrawString with the WrapWidth parameter. Only displays lines that are fully visible and if all text is not displayed last line will have an ellipsis even if that line fits in the cell (ends a paragraph)

You also have control of lines spacing as well as horizontal alignment.

The New URL for my website is www.KAtkoSoft.com.

  • Karen

For some reason the trailing dot threw the URL bad. Here it is again, corrected : http://www.katkosoft.com/

Congratulations, Karen.

Any solution for this ? so far it seems that still we cannot have word wrap in the cell.