RowImageAt for expanded listbox

Hey everyone - just started noodling with Xojo. Managed to get a sort of hierarchical left menu thing going on. I wanted to have a small icon followed by text in an expanded listbox.

Simple enough, I added a PaintCellBackground event handler to the listbox and am able to manually populate, like:

me.RowImageAt(0)=smallImage1
me.RowImageAt(1)=smallImage2
me.RowImageAt(2)=smallImage3

No trouble. Each of these items has sub-items, though, and the row images end up continuing into the expanded menu. For instance, if there are 5 sub items inside item 1 and I expand item 1, all three end up with the image.

How do I keep these images associated with the MAIN items in a hierarchical view, while giving the SUB items in expanded view their own images?

Thanks!

PaintCellBackground is the wrong place to assign RowImages. Assign them in ExpandRow.

Welcome, @Joe_Granato! May your Xojo noodlings be fruitful :smiley:

Thanks, but I guess I’m still a bit confused. I am able to add three rows, each with an image, in the Opening event for this listbox.

I am able to add expandable rows to nest under each of these rows in the opening event for this listbox.

In the Row Expanded event, I have sub items. I would like to set the images of the sub items. However, I’m not sure what to put for the argument. Effectively, I’m thinking of it like this:

MAIN ITEM 0
+++sub item 0
+++sub item 1
MAIN ITEM 1

When you open the program, MAIN ITEM 0 and MAIN ITEM 1 have their images. All good on that. If I expand MAIN ITEM 0, is that fundamentally changing the row count? Like, now instead of two rows, I have 4, and I have to name images for the newly expanded rows (1 and 2)? Is MAIN ITEM 1 now row 3?

That seems to be how it is behaving. I’m curious if there is an easy way just to keep images associated with all item and sub items, whether seen or unseen, without having to re-assess every collapse/expand.

Also, my PNGs, which have an alpha channel, are showing up with a white background. Suggestions on how to make them appear transparent? Thanks!

Yes.

Yes.

Yes.

This is how Listbox has behaved for as long as I’ve known it.

I tend to draw myself in CellBackgroundPaint (which fires for each cell on each row, so you’ll need to test your coordinates) instead of using RowImageAt.

As @Tim_Parnell said, yes to all. In my RowExpanded event handler, I add the rows that are now exposed. I look in an SQLite database to find out how many and what type of rows they are, since they can be an ordinary row ( → me.AddRow() ) or an expandable one ( → me.AddExpandableRow () ) . The thing recurses automatically.

Painting (such as adding an image) is done in the paint event.

I also have defined a class consisting of any variable I need to tell me all about the row (8 variables at the moment). I make a new instance of that for each row I add in RowExpanded, and make that instance be the row’s RowTag.

Gotcha. Huh. Ok. I am seeing it as too high level, I guess - that those things exist in the list array but are hidden. I guess if any variable interaction is happening with any of the items, I’ll have to keep track of what expandable windows are open, since the offset of main items could be dramatically different in value. There is probably an easier way to do that or think of it. But knowing I’m not crazy there helps a bit. Thanks!

Don’t worry too much about the changing row numbers, unless you store them for some reason. The event handlers will fire with the correct row numbers.

It gets more complicated if you plan to allow dragging of rows from one part of the structure to another.