Visual Basic Reference

ContainedControls Property

See Also    Example    Applies To

Returns a collection of the controls that were added to the control by the developer or the end user at the controls run-time. The ContainedControls property is not available at the controls authoring time, and read-only at the controls run time.

Syntax

object**.ContainedControls**

The ContainedControls property syntax has this part:

Part Description
object An object expression that evaluates to an object in the Applies To list.

Remarks

The ContainedControls collection is filled with all the controls that were added to the control by the developer or the end-user. The control can use the ContainedControls collection to perform operations on any of these contained controls.

This collection functions in a similar manner to the Controls collection on a form.

In order to allow contained controls to be placed on the control, the ControlContainer property must be True.

Contained controls cannot be added or removed through this ContainedControls collection; the contained controls must be changed in whatever manner the container allows.

The ContainedControls property may not be supported by all containers, even though the container may support the control having contained controls; Visual Basic forms do support this property. If this property is not supported, then calls to the ContainedControls collection will cause errors; use error handling when accessing the collection. Note, however, that if error handling is done while in an event procedure such as the InitProperties event procedure or the ReadProperties event procedure, the error handler should not raise an error event; doing this may be fatal to the container.

The ContainedControls collection is not available when the Initialize event is raised; but is available when the InitProperties event or ReadProperties event is raised.

Once the ContainedControls collection is present, it may not immediately contain references to the controls a developer has placed on the control. For example, if the control is on a Visual Basic form, the Count property of the ContainedControls collection will be zero until after the ReadProperties event procedure has executed.