Subclassed control events.

I could probably hunt around and find something that may work…but I’d appreciate a best practice tip before I develop a bad habit. I needed a “combo” box in my web app. One with the functionality of a popupmenu and textfield combined. So… I created one. I’ll call it BobsComboBox, and It works well enough. I respond to the “selection changed” event and update the text property of the textfield. My problem is that I also need to do something based on which “BobsComboBox” had it’s selection changed. I placed several of my “comboboxes” on the form and naturally none of them have a selection changed event (because they are a “custom” control). I didn’t want to kludge up the selection changed event with some sort of breaching based on the control name. I’d like to respond to a “selection changed” event that is relative to an instance of the control. What are the best ways to accomplish that?

Is your custom control a webcontainer? You can create your own event on the container control called “SelectionChanged” and when the popupmenu or textfield changes you raise the the SelectionChanged event of the container. Every instance you drag of your custom control you can decide to implement the SelectionChanged event with whatever logic you want. You can also lazily add a delegate to this event as well.

1)Add event definition to your ContainerControl called SelectionChanged
2)Add event implementation to your controls:

raiseEvent me.parent.SelectionChanged

or

raiseEvent self.SelectionChanged

Thank you very much Brock. I did see where I could add event definitions to custom controls…and that they can only be raised internally. It hadn’t occurred to me to add the event to the container control…and raise it from the internal popup. Makes perfect sense. The only “events” that show up in the instance are the Container control events. — so that’s the place to add the event. I get it. Thanks Again!