473,587 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple derivations from UserControl

I am writing a number of controls which use inheritance and I have a
problem that I do not know how to solve. It's best if I describe the
class structure I want.

Grid - derives from UserControl and contains most of the functionality
required of a basic grid.

ViewGrid, EditGrid and TreeGrid - all derive from Grid

The problem I have is that I never want the programmer to create an
object of type Grid - they should choose the derived class that best
fits their needs.

If these were normal classes then I would just declare the Grid class
as abstract and it would work as I would like it to. The problem is
that they derive from UserControl and the designer needs to create an
instance of Grid when I view EditGrid in the designer.

Another idea I had was to declare the Grid class as protected or
internal but then I cannot derive a public class from it.

Is there a way to specify that a UserControl derived class cannot be
created outside of the assembly that it is in and still enable it to be
created by the designer?

steve.kaye

Apr 6 '06 #1
7 2507

"steve.kaye " wrote...
If these were normal classes then I would just declare the Grid class
as abstract and it would work as I would like it to. The problem is
that they derive from UserControl and the designer needs to create an
instance of Grid when I view EditGrid in the designer.
I don't know why it needs to instantiate from Grid in your case. I have
abstract controls that I have been able to edit subclasses to in the
designer. Maybe you at some point instantiate it by "compositio n" in your
class EditGrid.

Anyway...
Another idea I had was to declare the Grid class as protected or
internal but then I cannot derive a public class from it.


You can declare the constructor of Grid internal.

// Bjorn A
Apr 6 '06 #2

Bjorn Abelli wrote:
"steve.kaye " wrote...
If these were normal classes then I would just declare the Grid class
as abstract and it would work as I would like it to. The problem is
that they derive from UserControl and the designer needs to create an
instance of Grid when I view EditGrid in the designer.


I don't know why it needs to instantiate from Grid in your case. I have
abstract controls that I have been able to edit subclasses to in the
designer. Maybe you at some point instantiate it by "compositio n" in your
class EditGrid.


I've not been programming in .NET for long so could you tell me what
you mean by "instantiat e it by "compositio n" "?

I have just tried this:

1) Start a new windows control library.
2) Rename the UserControl1 class to be BaseControl.
3) Change the BaseControl class to be abstract.
4) Build.
5) Add an Inherited UserControl to the project.

At this stage it would ask me to specify a class to derive from but it
warns me that no built assemblies contain components to inherit from
and advises me to build the current application or browse for a
previously built assembly from another application.

Another idea I had was to declare the Grid class as protected or
internal but then I cannot derive a public class from it.


You can declare the constructor of Grid internal.


This works but not as nicely as I would like. It still allows the
programmer to drag a Grid onto the form but it doesn't create the
object in InitializeCompo nent() because the constructor is not
accessible. I could use this method along with a comment in the
description of the control to not use it but use a derived class but I
would much rather avoid having the object in the toolbox to start with.

steve.kaye

Apr 6 '06 #3
"steve.kaye " wrote...
Bjorn Abelli wrote:
"steve.kaye " wrote...
> If these were normal classes then I would just declare the Grid class
> as abstract and it would work as I would like it to. The problem is
> that they derive from UserControl and the designer needs to create an
> instance of Grid when I view EditGrid in the designer.
I don't know why it needs to instantiate from Grid in your case. I have
abstract controls that I have been able to edit subclasses to in the
designer. Maybe you at some point instantiate it by "compositio n" in your
class EditGrid.


I've not been programming in .NET for long so could you tell me what
you mean by "instantiat e it by "compositio n" "?


It can mean a lot of things...

A control is in many cases "composed" of other controls (buttons,
textfields, etc).

What I meant in this case was if you on your EditGrid possibly had put an
instance of Grid itself. I can't see any other reason for EditGrid to
complain on an instantiation of Grid.

I still believe you should be able to declare Grid abstract.
I have just tried this:

1) Start a new windows control library.
2) Rename the UserControl1 class to be BaseControl.
3) Change the BaseControl class to be abstract.
4) Build.
5) Add an Inherited UserControl to the project.

At this stage it would ask me to specify a class to derive from but it
warns me that no built assemblies contain components to inherit from
and advises me to build the current application or browse for a
previously built assembly from another application.


Never happened to me.

My VS automagically detects which controls the project already has, and lets
me choose which one I want to inherit from.
> Another idea I had was to declare the Grid class as protected or
> internal but then I cannot derive a public class from it.


You can declare the constructor of Grid internal.


This works but not as nicely as I would like. It still allows the
programmer to drag a Grid onto the form but it doesn't create the
object in InitializeCompo nent() because the constructor is not
accessible. I could use this method along with a comment in the
description of the control to not use it but use a derived class but I
would much rather avoid having the object in the toolbox to start with.


Didn't happen to me either.

I don't know if I have a bug somewhere in my VS, but when I add the library
to my toolbox, somehow it seems to detect that the control with only an
internal constructor cannot be instantiated, hence only shows the derivated
controls.

// Bjorn A
Apr 6 '06 #4

Bjorn Abelli wrote:
I don't know if I have a bug somewhere in my VS, but when I add the library
to my toolbox, somehow it seems to detect that the control with only an
internal constructor cannot be instantiated, hence only shows the derivated
controls.


Are you deriving your controls from UserControl or from Control? I
have just tried the simple controls test but derived the base from
Control instead of UserControl and I was able to make the class
abstract and it disappeared from the toolbax which is what I wanted.

I didn't get the same behaviour with the internal constructor. It
still had it on my toolbox and allowed me to add it to the form but
without the grid1 = new Grid() bit.

I'll have a look into what I need to do extra when deriving from
Control rather than UserControl.

Thanks

steve.kaye

Apr 6 '06 #5

Bjorn Abelli wrote:
I don't know if I have a bug somewhere in my VS, but when I add the library
to my toolbox, somehow it seems to detect that the control with only an
internal constructor cannot be instantiated, hence only shows the derivated
controls.


Are you deriving your controls from UserControl or from Control? I
have just tried the simple controls test but derived the base from
Control instead of UserControl and I was able to make the class
abstract and it disappeared from the toolbax which is what I wanted.

I didn't get the same behaviour with the internal constructor. It
still had it on my toolbox and allowed me to add it to the form but
without the grid1 = new Grid() bit.

I'll have a look into what I need to do extra when deriving from
Control rather than UserControl.

Thanks

steve.kaye

Apr 6 '06 #6

steve.kaye wrote:
Bjorn Abelli wrote:
I don't know if I have a bug somewhere in my VS, but when I add the library
to my toolbox, somehow it seems to detect that the control with only an
internal constructor cannot be instantiated, hence only shows the derivated
controls.


Are you deriving your controls from UserControl or from Control? I
have just tried the simple controls test but derived the base from
Control instead of UserControl and I was able to make the class
abstract and it disappeared from the toolbax which is what I wanted.


I have encountered the same problem with the Control class now. MSDN
says that the base class of the object being passed to the designer is
not allowed to be abstract.

steve.kaye

Apr 6 '06 #7
"steve.kaye " wrotw...

Bjorn Abelli wrote:
I don't know if I have a bug somewhere in my VS, but when
I add the library to my toolbox, somehow it seems to detect
that the control with only an internal constructor cannot be
instantiated, hence only shows the derivated controls.
Are you deriving your controls from UserControl or from Control?


In this tryout I derived from UserControl.
I have just tried the simple controls test but derived the base from
Control instead of UserControl and I was able to make the class
abstract and it disappeared from the toolbax which is what I wanted.
Nice that it worked out for you.
I didn't get the same behaviour with the internal constructor. It
still had it on my toolbox and allowed me to add it to the form but
without the grid1 = new Grid() bit.

I'll have a look into what I need to do extra when deriving from
Control rather than UserControl.


What you'll be missing depends on what you need... ;-)

Maybe you could try to derive from ContainerContro l instead (the immediate
superclass of UserControl). You'll miss less features that way.

// Bjorn A
Apr 6 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1238
by: lothar.behrens | last post by:
Hi, I have a base class and virtually derived from them in two other classes. In turn I defined a class that derives from the two other class. Window < MasterWindow < < DetailWindow < \
2
1743
by: Andy Meyer | last post by:
Hi all, I'm converting some C++ Controls to C# and there's one big thing, that I can't solve: class CControlEx { int nDescriptionID; CString strDescription;
0
981
by: blackdevil1979 | last post by:
Hello, > "In COM, multiple inheritance between interfaces is not supported. However, by using the derived members capability, multiple inheritance can be simulated."..MSDN Library I have created an object which involve a datagrid. But when I create a form and try to use the object, I found that some of the property exists for a datagrid does not show in the usercontrol in the form, for example
9
4616
by: Quina | last post by:
Hi. Is there someone that can tell me how can I have multiple screens on the the same form, displaying only on at the time? Thank you all for any replys. João Carias
60
4898
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
9
3176
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will load with different data (locations, departments, etc.).
9
4288
by: moondaddy | last post by:
I'm using asp.net 2.0 and c# and would like to share some user control between several websites. these websites are on the same server and have a physical location right next to each other like this: D:\Websites\Website1 D:\Websites\Website2 I'm thinking of putting the controls for sharing in a common directory like this: D:\Websites\CommonControls
47
3989
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever support multiple inheritance. In C++ for instance I noticed that the compiler flags an error if you use the "ref" keyword on a class with multiple base classes. This supports the above quote. However, under the "CodeClass2.Bases" property (part...
2
2441
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, I am going to write a large application using Visual Studio C#. I am going to use only one Form as main menu and go to other pages by cliking on next button in each page. I dont want to create several forms and move from one form to next. However I need to have same action using only one form. Could someone show me how I can use only one form instead of multiple forms. Thanks -- Nejadian
0
7924
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7854
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.