MultiLine in Listbox

I’m trying to figure out how to display multiline text in a cell, and grow the height of the cells to properly show the text.

My text will have EndOfLine characters to split it into lines. It may be 1,2 or maybe up to 5 lines.

I know I use g.DrawString In the CellTextPaint event.

What I can’t figure out is how to size things on the fly, based on how many lines, and accounting for font height.

Any tips appreciated

I can’t remember offhand whether a listbox can have rows that are not all the same height.

There is g.TextHeight which tells you how high the overall text is for a given text string in a certain width (given that it may wrap).

Last I saw, the rows all have to be the same height. I guess what I’m looking for is how get the aggregated height of all the lines, then increase the default row height to that.

Well, you have the cell width, so that’s your wrap value. Then use g.TextHeight to get the height that your chunk of text will occupy. That’s then your row height. I don’t know whether explicit line ends work properly with that, so it may be a case of doing it for each bit and then adding them up. So you may need to experiment a little.

If text with lineends needs special treatment, split the text into an array on lineend and then a simple loop over the array should work nicely. But that may not be necessary.

Listbox does not support variable row heights out of the box. @KarenA created a listbox class that can merge rows and delivers a lot more flexibility. It may be API 1, if that makes a difference.

You could look into DataView by piDog Software: DataView