Adding a UserControl to the Component Tray

I

ian.kemp

I have a base UserControl class - DataModule - to which I have added a
SqlConnection and a DataSet. The idea is that users will build on this
base class, adding their own SqlCommands as needed, but always using
the same connection/dataset (i.e. a simple API). The reason for using a
UserControl, is to allow users to drag-and-drop SqlCommands etc. from
the Toolbox directly onto the design area; they can then select those
objects from the Component Tray and edit their properties.

These subclasses of DataModule will then be placed onto another
UserControl containing a DataGridView, and the user will connect the
DataModule's DataSet to the grid's DataSource. So far, I've got the
above working great.

However, when I drop a DataModule subclass onto a UserControl, the
DataModule is placed on that UserControl's canvas. Because DataModule
itself isn't meant to be used as a visual component, it makes more
sense for it to appear in the Component Tray instead; however, I can't
seem to get this to work. (I've tried the DesignTimeVisible attribute,
as well as others.)
From what I've read, it seems that any component that's a subclass of
Control cannot be displayed in the Component Tray. Is this correct, and
if so, is there any way to work around this?

Also, if you think this implementation is incorrect, please tell me!

(I am using .NET 2.0 with Visual Studio 2005 Professional.)

TIA.
 
B

Bob Powell [MVP]

Basing non graphical classes on UserControl is impossible. You need to
change the base class to Component, then it will appear in the component
tray as desired.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top