Populate listbox using addrow or rowtag and CellbackgroundPaint

In a Windows Desktop app i am using different textsizes, colors, etc. in serveral listboxes

Is it better to add the rows with “addrow”, the classical way, and formating the text with celltextpaint,
or adding a class with the content to the rowtag and drawing the text with cellbackgroundpaint (g.drawstring), the way i prefer.

What do you think?

Paint the Text in the CellTextPaint event. That’s where the Text should be painted :wink:

OK Sascha, i know that it “should” be there, but do you thin it is a problem to paint it the other way?
I prefer it, because i have more options, for example 2 lines in one cell.

? - But you can do the same in the CellTextPaint Event…

I prefer the recommended way because if i start to manipulate the Background (Selection and alike), i have no issues with the Paint Order.

uhh…ok,
didn’t know that you can do this in the CellTextPaint-Event as well.

But nevertheless my focus is more on the question addrow(“content1”,“content2”…) vs. adding a class with the data to the row-tag or cell-tag, and “painting” it into the columns.
I’m thinking about performance-differences, etc.

[quote=458879:@Tim Wolff]OK Sascha, i know that it “should” be there, but do you thin it is a problem to paint it the other way?
[/quote]

It can be done. That is what I had to do for my MergedCell Listbox…

To mimic exactly how the listbox would do things is non trivial however.

It means you have to handle painting the CellBackground when selected or not as well as then using the right text color for the background and match what the listbox would do on its own. The colors depend on OS settings,

Also the text paint area is smaller than the cell backround paint area - there is a few pixel area on each side where background paint can draw but text paint can not.

You also need to determine text position due to checkbox (if present) and hierarchical indents (The Text Area is less then the background area) as well as the alignment set for the cell.

It’s all doable (I did it) - but it’s a bit of work to get it to line up exactly.

  • Karen

myself store the object with data in the rowtag or celltag. in case you have a database behind you often need the record id.
if you need to paint text see TextShape before Xojo R2 is was StringShape

[quote=458900:@Markus Rauch]myself store the object with data in the rowtag or celltag. in case you have a database behind you often need the record id.
if you need to paint text see TextShape before Xojo R2 is was StringShape[/quote]
Markus, this is cool, never heard of StringShape before…