ContainerControl Event

Hi, I have created a container control with 4 checkbox and a text field. I have then created 6 instances of this container in the main windows and all are correctly displayed. my problem is the following I would like to have an event raised when clicking on any of the checkbox telling which checkbox from which container has been clicked. I have done searches with no result (may be it can’t be done).
I would like to know if someone can give some hints on how to do this
thanks a lot

You can create your own event and call it yourself.

To do so, add a “New Event Definition” to the ContainerControl, and call it “CheckboxClicked(cb As String)”. Then in each of the individual CheckBox action events, you can call CheckBoxClicked(“SomeTextToIdentifyTheCheckbox”).

When you put the Container onto a Window, you can then add the CheckboxClicked event handler where you can put code.

Just a @Paul Lefebvre said, but it might be a good idea to pass the Checkbox itself as the argument. Then you can do things like get its parent container etc… Subclassing the built in controls to add properties is also usually helpful.

You could do something like:
CheckBoxClicked(checkBox as myCustomCheckBox)

And have a property on myCustomCheckBox that determines what value or settings its tied to. You can even add this property to the IDE interface.

I have followed the steps up to the last line, when in Window1/add to Window1/event handler I can’t see the CheckBoxClicked event
am I doing something wrong?

The event handler is on the ContainerControl you added to the Window, not on the Window. So select the ContainerControl on the Window and then choose Add Event Handler.

THANKS A LOT, this works fine.

I have created an array of container control:
dim x,y As integer
dim test(4,4) as ContainerText
for x=1 to 4
for y=1 to 4
test(x,y) = new ContainerText
test(x,y).EmbedWithin(self, 216x, 140y)
next y
next x

in each container I have a checkbox, i would like to know if I can retrieve the container info i.e. text(x,y) where the checkbox is located


Look up AddHandler. This allows you to tie the event from the Container to a method. One of the parameters that will be passed in is the instance of the container.

If you really code it this way, your array will go out of scope when the method ends, so you won’t be able to find the indexes later. It should be a property of the window.

That said, the easiest way would be to add X and Y properties to the container and set them when you create it.

test(x,y) = New ContainerText
test(x,y).X = x
test(x,y).Y = y

If the indexes are volatile, then you could add an event to the container that requests the x,y indexes. Implement that event in the window and tie it to each container via AddHandler.

But really, what do you expect to do with that information?