Non-visible listbox firing paint events

I’ve been porting an application from RB to Xojo and have run into an issue.
I’ve got a window. A container control is embedded within it at runtime. The container control consists of a pagepanel (6 panels) with various controls on each panel. The problem is a listbox on panel 5. During the embed method, the listbox’s CellBackgroundPaint event is firing, which is causing an OutOfBounds exception due to the variables it relies on not being loaded yet (they are loaded based on the user’s activity). Since the listbox is on panel 5 and the pagepanel starts off on panel 0, I don’t expect the CellBackgroundPaint event to fire (since its not visible). In RB it works as expected, but in Xojo I’m getting the exception. I’ve verified in the dubugger that the listbox’s parent is the pagepanel and the panel index is 5.

To make it stranger, I’ve got another container control which is very similar to the problem one, but this issue is not happening! Anyone in Xojoland have any insights for me?

If me.ListCount = 0 then Return ?

Thanks for replying Jym. I can avoid the exception with a simple if statement at the top of the event. My question is, is this a bug? It seems that when a container control is embedded, all of the controls are drawn first on panel zero, then hidden after all the controls are initialized (there are a large number of controls on the CC). I simply do not expect that a control on panel five would fire a paint event when that panel isn’t even showing.