PC Review


Reply
Thread Tools Rate Thread

Components added to a Components Surface not in Components Collection?

 
 
Microsoft
Guest
Posts: n/a
 
      19th Feb 2004
I've created a Component called MyComponent. To the design surface of
MyComponent I've dragged an SqlConnection object, an SqlCommand object, and
an SqlDataAdapter object and linked these items together appropriately.

My question is this: Why are these Sql components not added to the list of
components contained by MyComponent? (These objects are not added to the
private "components" member of MyComponent.) Is there a technical reason
for this or is it just a bug in the designer? Is there any way I can get
the Designer to add these items to the collection automatically, without
having to hand-code it myself?

Thanks,
-Dave


 
Reply With Quote
 
 
 
 
Peter Huang
Guest
Posts: n/a
 
      20th Feb 2004
Hi Dave,

Thanks for posting in the community.

>My question is this: Why are these Sql components not added to the list of
>components contained by MyComponent? (These objects are not added to the
>private "components" member of MyComponent.)

This is because the Sql components did not implement the contructor as
below.
Public Sub New(ByVal Container As System.ComponentModel.IContainer)
Me.New()
Container.Add(Me)
End Sub

For detailed information, you may take a look at the article below.
What's that "Windows Form Designer generated code" anyway?
http://www.vbinfozine.com/a_disposable_comp.shtml


>Is there any way I can get
>the Designer to add these items to the collection automatically, without
>having to hand-code it myself?

Since the SQLDataAdapter is an sealed class, it can not be derived, I think
we need to do it by coding ourselves.

As for the other question, I am doing researching, if I have any new
information, I will update you with ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Microsoft
Guest
Posts: n/a
 
      20th Feb 2004
Thanks for the input. The reason I ask this question is that at run-time I
am simply trying to initialize my SqlConnection object to supply it with the
connection string that is known at run time as well as handling messages
returned from the InfoMessage event. I understand there are many ways of
doing this, but I'm trying to automate the process within designer as much
as possible.

My goal was to create a ConnectionHandler component that would implement the
ISupportInitialize interface. Within the ISupportInitialize.EndInit() method
for this component, I wanted to iterate through the list of components
hosted by my container object, find the SqlConnection object, and then do my
initializations. The result (if this had worked) would be that my container
component (whether it was a Windows Form, ASP.NET Page, or another
Component), could be programmed almost completely through the designer and
have the run-time functionality I desired. The problem is, obviously, that
my SqlConnection object is never added to the container object's list of
hosted components and thus my ConnectionHandler object can't find it.

Of course, if you allocate the SqlConnection object yourself within the
component constructor, it is simple enough to add to the list of components,
but of course you lose functionality within the designer, such as editing
properties or viewing a DataSet. This is because the SqlConnection object
is no longer on the design surface of the container component.

Also, adding the SqlConnection (or any other contained object, for that
matter) after the call to InitializeComponent() has finished, you lose the
ability to take advantage of the ISupportInitialize() interface. When it's
time to add the component to the collection, the EndInit() method has
already been called on the contained components.

I'm probably making a mountain out of a molehill here. I've got plenty of
ways to work around this limitation. However, it would have been nice for
the designer to properly add any Component-derived objects to its collection
automatically.

-Dave


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error while invoking the COM+ components developed using .Net (Serviced Components) Praveen Chandra Microsoft Dot NET 4 21st Jun 2006 07:47 AM
How to Get a Custom Component Added to a Form's Components Collection Don Microsoft VB .NET 0 27th Jan 2006 04:46 PM
project with serviced components and non services components z f Microsoft ADO .NET 4 6th Oct 2005 02:14 PM
What is the difference between framework components and application components? Julia Microsoft C# .NET 2 22nd Nov 2004 02:48 PM
UnHiding Games components in add/ remove components Mark Microsoft Windows 2000 Registry Archive 0 11th Sep 2003 04:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 PM.