Listbox behaving differently (wrongly) on Windows

I have a Listbox subclass which simply implements the CellBackgroundPaint event to draw a fixed background on the listbox.
When the listbox is scrolled, the background remains unchanged, it just redraws on the newly visible cells.

This is the code in CellBackgroundPaint event:

g.drawPicture(pic1, 0, 0, g.width, g.height, me.left,*g.height), g.width, g.height)

where pic1 is whatever picture

On Mac, this works properly, but NOT on Windows. Scrolling on Windows, leave the trails of the last cell over all the listbox.
After investigation, it seems the problem is Windows doesn’t redraw all cells after the listbox scrolls, just the first or last, depending on the scroll direction. But this is not correct, because all cells changed.

I already filed a bug report with an example project:

Now, is there a way to force the Windows listbox to invalidate all cells? I already tried something but with no avail.
Any ideas or workarounds?

Thanks in advance.

Did you return true in the CellBackgroundPaint event? That tells the framework to not draw the default over it.

I don’t return True because I want the standard highlight, however I tried returning True and changed nothing.

You need to invalidate all of the cells you draw parts of the picture in (or that it was in before the scroll and now are empty)

I will tell you from experience that it is VERY tricky to get this right xplatform, but it can be done.

BTW IMO you are better off doing the row selection highlight yourself. The painting of the highlight happens at different times om Mac Vs Windows IIRC.

I tried doing an InvalidateCell(-1,-1) which should invalidate all cells. Nothing changed. Same for invalidating selectively the required cells.
The problem here, is that I know I have to invalidate cells during the CellBackgroundPaint, and doing an invalidateCell here I believe it should fire again the same event … to an infinite loop. But this doesn’t happen, strangely.
The best would be to have an event which informs me about the scroll, but I didn’t found one.

i had to use Timers

You an create a scrolled event in CellBackground paint that just fires once per scroll

And this works!
I set a timer with a period of 0 which fires once in the CellBackgroundPaint.
The Timer.Action event does an invalidateCell(-1, -1).
Unfortunately It flickers, but at least works.

I think the Listbox has some mechanism to limit the refresh, and that’s why if you invalidateCell in CellBackgroundPaint event it’s ignored. Same if you try to invalidate a cell which doesn’t exists.

Thanks Karen fro your suggestion.