473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get all child components from base class

I have a custom UserControl, which can have many sub class levels
derived from it. I want to be able to discover all the components at
Load time, but the only components I can see from the base class
are the private components internal to the base class itself. What
I want are ALL components for the entire class no matter how many
levels of sub-classing this particular control contains.
I do not want to have to force the child classes to implement a method
so that the base class can get access to its components. It would
like to hide this fact from the child classes, and just handle it in the
base. Is there any way at all I can do this ?

Thanks in advance

JIM

Nov 13 '05 #1
4 9779
James,

I don't think that this is possible. The parents have no sense of the
children unless the children explicitly expose something that the parent can
access. If the parent has to know what classes can derive from it, then it
would make things very hairy, since the possibility of a class deriving from
it would be high, and difficult to track (how do you know there is not a
class in some assembly that derives from you, and how do you dynamically
link to it and access the type? It's just not possible).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"james" <no****@hyperco n.net> wrote in message
news:Oc******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a custom UserControl, which can have many sub class levels
derived from it. I want to be able to discover all the components at
Load time, but the only components I can see from the base class
are the private components internal to the base class itself. What
I want are ALL components for the entire class no matter how many
levels of sub-classing this particular control contains.
I do not want to have to force the child classes to implement a method
so that the base class can get access to its components. It would
like to hide this fact from the child classes, and just handle it in the
base. Is there any way at all I can do this ?

Thanks in advance

JIM

Nov 13 '05 #2
Well, actually what you say isn't totally correct. Since this is a
UserControl,
all sub classes will always be user controls, and since my Base class can
handle the Load event, It does not need to know anything about the subclass
because it already knows that all UserControls are the same, they have
components.
So, while you are probably correct on the point that it isn't possible due
to the protection level, your second point about sub classes in different
assemblies does not follow in this particular case.

This brings up a design flaw in Controls that I have always thought could be
made better. Why does each sub-class have it's own private components.
Shouldn't the components be protected instead, so that each sub-class shares
the list and can add it components to that shared list ?

Thanks

JIM
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:eH******** ******@TK2MSFTN GP12.phx.gbl...
James,

I don't think that this is possible. The parents have no sense of the
children unless the children explicitly expose something that the parent can access. If the parent has to know what classes can derive from it, then it would make things very hairy, since the possibility of a class deriving from it would be high, and difficult to track (how do you know there is not a
class in some assembly that derives from you, and how do you dynamically
link to it and access the type? It's just not possible).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"james" <no****@hyperco n.net> wrote in message
news:Oc******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a custom UserControl, which can have many sub class levels
derived from it. I want to be able to discover all the components at
Load time, but the only components I can see from the base class
are the private components internal to the base class itself. What
I want are ALL components for the entire class no matter how many
levels of sub-classing this particular control contains.
I do not want to have to force the child classes to implement a method
so that the base class can get access to its components. It would
like to hide this fact from the child classes, and just handle it in the
base. Is there any way at all I can do this ?

Thanks in advance

JIM


Nov 13 '05 #3
James,

This is something that is easily remedied. You can make it so that the
classes that you design all implement a pattern such that they expose their
components in a way that is accessible through a sub-class. Just have a
protected property which has the components.

Or do you need to be able to access this information for any type?
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"james" <no****@hyperco n.net> wrote in message
news:ey******** ******@TK2MSFTN GP12.phx.gbl...
Well, actually what you say isn't totally correct. Since this is a
UserControl,
all sub classes will always be user controls, and since my Base class can
handle the Load event, It does not need to know anything about the subclass because it already knows that all UserControls are the same, they have
components.
So, while you are probably correct on the point that it isn't possible due
to the protection level, your second point about sub classes in different
assemblies does not follow in this particular case.

This brings up a design flaw in Controls that I have always thought could be made better. Why does each sub-class have it's own private components.
Shouldn't the components be protected instead, so that each sub-class shares the list and can add it components to that shared list ?

Thanks

JIM
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote in message news:eH******** ******@TK2MSFTN GP12.phx.gbl...
James,

I don't think that this is possible. The parents have no sense of the children unless the children explicitly expose something that the parent

can
access. If the parent has to know what classes can derive from it, then

it
would make things very hairy, since the possibility of a class deriving

from
it would be high, and difficult to track (how do you know there is not a
class in some assembly that derives from you, and how do you dynamically
link to it and access the type? It's just not possible).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"james" <no****@hyperco n.net> wrote in message
news:Oc******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a custom UserControl, which can have many sub class levels
derived from it. I want to be able to discover all the components at
Load time, but the only components I can see from the base class
are the private components internal to the base class itself. What
I want are ALL components for the entire class no matter how many
levels of sub-classing this particular control contains.
I do not want to have to force the child classes to implement a method
so that the base class can get access to its components. It would
like to hide this fact from the child classes, and just handle it in the base. Is there any way at all I can do this ?

Thanks in advance

JIM



Nov 13 '05 #4
Nicholas,

You are correct, I can do this, but not exactly the way you describe.
The method would have to be recursive, with the base class calling it
at load time, then the bottom most child class adding his components to
an IList and appending his parents components via a recursive call
and so on, so that each class, on up to the root will append their
components
to the IList, then the root class will have one big IList of all components.
Remember, I can have an unlimited number of child classes like so
A->B->C->D with A being the root control and D being the child.
Each class, A, B, C, D will have components.

The problem with this solution is that I have to copy/re-implement the same
routine in each child class, which leaves room for error. What if the
designer of class C or D does not implement it correctly.

I would rather do it all from the root, hiding the fact from B, C, and D
that
anything is happening
JIM
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:eO******** *****@TK2MSFTNG P11.phx.gbl...
James,

This is something that is easily remedied. You can make it so that the classes that you design all implement a pattern such that they expose their components in a way that is accessible through a sub-class. Just have a
protected property which has the components.

Or do you need to be able to access this information for any type?
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"james" <no****@hyperco n.net> wrote in message
news:ey******** ******@TK2MSFTN GP12.phx.gbl...
Well, actually what you say isn't totally correct. Since this is a
UserControl,
all sub classes will always be user controls, and since my Base class can
handle the Load event, It does not need to know anything about the subclass
because it already knows that all UserControls are the same, they have
components.
So, while you are probably correct on the point that it isn't possible due to the protection level, your second point about sub classes in different assemblies does not follow in this particular case.

This brings up a design flaw in Controls that I have always thought could be
made better. Why does each sub-class have it's own private components.
Shouldn't the components be protected instead, so that each sub-class

shares
the list and can add it components to that shared list ?

Thanks

JIM
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com>

wrote
in message news:eH******** ******@TK2MSFTN GP12.phx.gbl...
James,

I don't think that this is possible. The parents have no sense of

the children unless the children explicitly expose something that the parent can
access. If the parent has to know what classes can derive from it,
then
it
would make things very hairy, since the possibility of a class
deriving from
it would be high, and difficult to track (how do you know there is not

a class in some assembly that derives from you, and how do you dynamically link to it and access the type? It's just not possible).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"james" <no****@hyperco n.net> wrote in message
news:Oc******** ********@TK2MSF TNGP12.phx.gbl. ..
> I have a custom UserControl, which can have many sub class levels
> derived from it. I want to be able to discover all the components at > Load time, but the only components I can see from the base class
> are the private components internal to the base class itself. What
> I want are ALL components for the entire class no matter how many
> levels of sub-classing this particular control contains.
> I do not want to have to force the child classes to implement a method > so that the base class can get access to its components. It would
> like to hide this fact from the child classes, and just handle it in

the > base. Is there any way at all I can do this ?
>
> Thanks in advance
>
> JIM
>
>
>



Nov 13 '05 #5

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

Similar topics

0
2509
by: sshuangw | last post by:
Hello: I am encountering a very weird issue with MDI child, Overriden WndProc function and hidden form. Basically, the application has two forms, Form1(parent form), Form2(Child form), Form2's WndProc method is overriden, if the message is CLOSE message, just hide the form. I first initialize and show the child form, then close it by clicking the Close(X) button, the overriden WndProc method gets invoked, and the form is hidden. Then
3
5615
by: James Spibey | last post by:
Hi, I have an MDI application which has aboout 10 child windows. The way the app needs to work is that only one window should be visible at a time and it should be maximized within the parent window. I have set all my child windows to be WindowState.Maximized but after showing 2 or 3 windows, the windows all drop back to Normal state. I have tried various things to overcome this inclusing overriding OnResize etc but none seem to give...
3
9701
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI parent menu functions. if i select draw line in MDI parent, the line should be drawn in current active child..any URLS for this or guide me to achieve this communication... -- Mähésh Kumär. R
2
6874
by: brianbender | last post by:
I am trying to load and unload assemblies dynamically and call methods and properties when loaded into an Appdomain I can load assemblies all day in the current AppDomain without references and without interfaces if need be. But try as I may they will ot unload. I have been working on this problem for weeks. I have seen other apps using Remoting but I know there has got to be a way to create a child AppDomain and reference obkect via...
10
1543
by: Peter Oliphant | last post by:
Is there a way of defining a method in a base class such that derived classes will call their own version, EVEN if the derived instance is referred to by a pointer to the base class? Note that the base class method is not to be abstract, and will be called if the instance was created as a 'generic' base class instance. It's sort of like I want the method to be abstract to children, but concrete at the base level. That way I can refer to...
4
4569
by: Danny Tuppeny | last post by:
Hi all, I've been trying to write some classes, so when I have a parent-child relationship, such as with Folders in my application, I don't have to remember to add a parent reference, as well as adding to the child collection, eg: parent.Children.Add(child); child.Parent = parent;
0
1880
by: Bruin | last post by:
Hi All, I'm having a problem with MDI child forms when the reference to the MDI Parent is set in a Control library. (Sorry for the long post) I have an control library assembly which holds all of my base classes including my base MDI Container form and my base MDI child form the mdi container has a singleton which returns an
2
2160
by: Lenster | last post by:
Environment --------------- Visual Studio.NET 2003 Version 7.1.3088 ..NET Framework 1.1 Version 1.1.4322 SP1 XP Professional 5.1.2600 SP2 Build 2600 Problem Description ----------------------- I have an mdi parent form.
1
14561
by: sklett | last post by:
I've read several articles/blogs/threads about anchoring/docking child controls in a FlowLayoutPanel. It sounds like it *should* work, but I can't get it to work for the life of me. Jon Skeet: I've created a short and complete sample to illustrate the problem. Beat you to it! :0) I would really appreciate if anyone could take a look at this and tell me what the magic trick is to make this work. All I want is to have the child...
0
8946
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
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
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...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
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
6735
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
4550
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
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.