PRB: ParentControls Property May Not Work with Some Containers
ID: Q235414
|
The information in this article applies to:
-
Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 5.0, 6.0
SYMPTOMS
The ParentControls Collection of a Visual Basic UserControl is empty when the control is placed in a non-Visual Basic Container.
CAUSE
The ParentControls property is designed to return a Collection of all the controls situated on a Form, UserDocument, or other UserControl. This property is exposed by the Visual Basic extender object, and it is the responsibility of the host container to implement the code needed to fill the collection. Not all containers will support this feature. Consequently, this property might return an empty collection in containers that do not support it.
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Build Control
- Start Visual Basic and select New ActiveX Control. UserControl1 is created by default.
- Change the name of the UserControl1 to MyControl and the Project name to MyControlServer.
- Place a listbox and a CommandButton on the control, and in the click event of the CommandButton, put the following code:
List1.Clear
Dim x As Object
For Each x In UserControl.ParentControls
List1.AddItem x.Name
Next
- Save the project and compile to build an OCX.
Steps to Create a Visual Basic Container
- Start Visual Basic and select New Standard EXE. Form1 is created by default.
- Place a few controls on Form1. (The type of controls is not important.)
- From the Project menu, select Components. From the Components list, select MyControlServer to add your custom control to the control toolbox.
- Insert an instance of this control on Form1.
- Run the project by pressing the F5 key. When you click on the CommandButton of MyControl1, the list box will be filled with all the names of the controls on Form1 (including your custom control).
Steps to Create a Visual Basic for Applications Container
- Start Microsoft Word and go to the Visual Basic Editor (ALT+F11).
- Insert a UserForm in your project.
- Place a few controls on the form. (The type of controls is not important.)
- Click the right-mouse button on the Toolbox Controls and select Additional Controls.
- Select MyControlServer.MyControl from the list.
- Insert an instance of this control on the form.
- Run the form and click on the CommandButton of your custom control. You will notice that the list box is not filled because the ParentControls Collection is empty. The Collection is empty because VBA does not implement this property.
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Harsha Bennur, Microsoft Corporation
Additional query words:
Keywords : kbCtrlCreate kbVBp500 kbVBp600 kbGrpDSO kbDSupport
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbprb