Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / May 2004

Tip: Looking for answers? Try searching our database.

Querying components in ComponentTray.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KK - 24 May 2004 05:38 GMT
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
Chris Langston - 28 May 2004 14:53 GMT
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

> Hi
>
[quoted text clipped - 26 lines]
> Help!
> KK
Ernest Morariu - 28 May 2004 17:16 GMT
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

> 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
[quoted text clipped - 82 lines]
> > Help!
> > KK

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.