all groups > dotnet windows forms designtime > may 2004 >
You're in the

dotnet windows forms designtime

group:

Querying components in ComponentTray.


Querying components in ComponentTray. KK
5/24/2004 10:38:35 AM
dotnet windows forms designtime:


Hi

I am developing a user control and for that
I need to query the component tray controls
to find out wether there are any controls
such as errorProvider added to the project.

If so, I have to list them in my user controls
property browser. The problem is that
I couldn't found any information on querying
the components added to ComponentTray.

Couple of hints I receievd was to query the
Site of a control and iterate its container.
Which I have trided but alway returns null.

Have any body tried doing this and
got positive results?

Note: I dont want to query the component
variable which gets added to the form. What
I want is to QUERY all the compoents added
to COMPONENT TRAY.

I know, I have to do some meddling with
Design time support, but the help avialable
is extremely limited.

Help!
KK

Re: Querying components in ComponentTray. Chris Langston
5/28/2004 9:53:35 AM
We are using a technique similar to what you are asking for.
It's kind of complicated, but you must ensure that you have added your
custom component to the IContainer collection.

The Windows form designer should create a IContainer instance called
components.
Private components As System.ComponentModel.IContainer when the form is
created. When you drop your control onto the System Tray, this component
should be added to the components collection.

For the custom control that you are creating, you need to make sure you have
a Constructor that will take an IContainer instance.

When you drop this control on your form, the Windows Form designer should
call the right construtor passing the components instance.

Me.CustomComponent = New MyCompany.MyProject.CustomComponent(Me.components)



This is the constructor of your CustomComponent.

Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyBase.New()

InitializeComponent()

'This is the step where your new custom component will be added to the
Container class that is passed in through the constructor.
Container.Add(Me)

End Sub



Then what we have is a WireCustomComponents routine that does the following:

Public Overloads Sub WireCustomComponents(ByVal components As IContainer)

If components Is Nothing = False Then

For Each eComponent As IComponent In components.Components

If TypeOf eComponent Is CustomComponent Then

'Do something with your custom component



'Our component has a Property Named ParentComponentID as String
'You will need to cast the component back to the appropriate type
from the collection.

Dim parentList As String = CType(eComponent,
CustomComponent).ParentComponentID()

End If

Next

End If









[quoted text, click to view]

Re: Querying components in ComponentTray. Ernest Morariu
5/28/2004 6:16:22 PM
Chris,

I am also interested in this subject.
The solution you suggested works fine with the components(the components i
build this way), but you know that, for instance, the class DataAdapter
class do not have constructor taking IContainer parameter, but it still
apears System Tray without being a item in the collection
components.Components.
So, the :
For Each eComponent As IComponent In components.Components

cannot "see" all the object in the SystemTray, but just the ones having a
constructor taking an IComponent parameter.

Did you find any explanation on how these particular objects(like
DataAdapter) are added to the System Tray and what would be the collection
containing them?

Ernest



[quoted text, click to view]

AddThis Social Bookmark Button