Referencing a method on a container from another dynamically embedded container

Having struggled with this for a while, I thought I’d share a solution I’ve discovered. Sorry if this is obvious to others.

I have a container control called ccWebSelectorItem which contains a label and an Image.
I am programmatically adding instances of ccWebSelectorItem to another container control called ccWebSelector using the EmbedWithin function.
On the ccWebSelector class I have a method called ItemClick which records which ccWebSelectorItem was clicked.

On the ccWebSelectorItem class, I am responding the label MouseUp event. What I wanted to achieve was to call ccWebSelector.ItemClick method from the MouseUp event of the label on the ccWebSelectorItem, and pass in the parent ccWebSelectorItem of the label.
(I hope you can follow all that!)

Here’s what I did.

In the MouseUp event of the label I put:


Simple! But not obvious.

Any alternative solutions would be gratefully received.

Instead of using Me.Parent you could use Self. Self always points to the containing webview (webpage, webcontainer or webdialog). Also, if you have already typed the parameter in ItemClick as a ccWebSelectorItem, then you don’t need to cast it in the method call. So your code would be:


It does the same thing, just a little cleaner.

Thanks Jay! That’s great.