I am getting this error message: "Select of a control that is within a container control, such as a gallery, from outside the container. Select can be used within a container control when both controls are within the same container."

I am using the Select(Gallery Name, Row Number) function
to select the gallery and the particular row in the gallery.
Select(SPRGallery, cvSPRGalleryRowNumber);
The Select() function is being executed in the screen's OnVisible event.

The selected row is highlighted using the gallery's TemplateFill property.
But sometimes I get this error message.

Can someone explain why I am getting this error?
But the error does not occur every time.