Iterate through controls?

I’ve embedded a bunch of controls in another control.
How do I itterate over the contents of the parent control to close all embedded controls?

You will need to keep track of all of these embedded controls. Typically I add an array property on the parent container.

myContainers() as webcontainer <–Add this to the parent container

After you embed the container, add it to the mycontainers array

myContainers.Append(container)

When you close a container remember to remove it from the myContainers array first.

Embedded controls can be retrieved via WebContainer.ControlAtIndex. Of course this iterates over all controls so you have to have a way to identify the controls you’ve embedded. Type checking via IsA works.

Adding a property is easier in that you don’t have to find your embedded controls vs. other static controls. But use WeakRefs if you do this. Storing the child container directly in a property of the parent leads to a circular reference. If anything goes wrong and the child is not deleted from the property before the parent or parent page closes then you’ve got a memory leak. (I just tested this to confirm.)

My object inherits from WebContainer

[code]Sub CloseAll(V as MyView)
dim ctrl as WebContainer

for each ctrl in v
if ctrl isa WebContainer then
ctrl.close
end if
next

End Sub
[/code]

However I’m getting this error message which I do not understand on the for each statement.

Use a simple for not a for each…

dim ctrl as WebContainer

For i As Integer = 0 To v.ControlCount-1
ctrl = v.ControlAtIndex(i)
if ctrl isa WebContainer then
ctrl.close
end if
Next