473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Test whether a control is a container

Is there a simple way to test if a control is a container type control
(e.g. groupbox, panel etc)

I realise that all container controls have to by definition, have the
System.ComponentModel.DesignerAttribute. If there is an easy way to
query whether a control has this attribute, this may well be the way
forward. I'm not sure how to do this.

Or is there a different way?

Greg.

Nov 15 '06 #1
6 3212

Greg wrote:
Is there a simple way to test if a control is a container type control
(e.g. groupbox, panel etc)

I realise that all container controls have to by definition, have the
System.ComponentModel.DesignerAttribute. If there is an easy way to
query whether a control has this attribute, this may well be the way
forward. I'm not sure how to do this.

Or is there a different way?

Greg.
I'm not quite sure what you are asking. Any control derived from the
Control
class will have a "Controls" member that can contain other controls. If
you
want to know if it can support children, the derivation from Control
will tell
you that.

Matt

Nov 15 '06 #2


"Greg" <sp**********@yahoo.co.ukwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Is there a simple way to test if a control is a container type control
(e.g. groupbox, panel etc)

I realise that all container controls have to by definition, have the
System.ComponentModel.DesignerAttribute. If there is an easy way to
query whether a control has this attribute, this may well be the way
forward. I'm not sure how to do this.

Or is there a different way?

Greg.
Although Matt's reply is true, you could check the instance in question to
see if it implements the IContainer interface.

HTH,
Mythran
Nov 15 '06 #3

Mythran wrote:
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Is there a simple way to test if a control is a container type control
(e.g. groupbox, panel etc)

I realise that all container controls have to by definition, have the
System.ComponentModel.DesignerAttribute. If there is an easy way to
query whether a control has this attribute, this may well be the way
forward. I'm not sure how to do this.

Or is there a different way?

Greg.

Although Matt's reply is true, you could check the instance in question to
see if it implements the IContainer interface.
I knew I should have taken the extra second to look at the interfaces.
Yours
is a much better answer. Honestly, though, I'm still not sure what
problem he
is trying to solve. Virtually every control implements IContainer.

Matt

Nov 15 '06 #4
Thanks Matt and Mythran.

I currently have a method that does some work on a control reference
passed to it. It needs to be understand whether the control passed to
it is capable of containing other controls - the current list being for
a winforms app:
FlowLayoutPanel
Panel
SplitContainer
TabControl (and tabpage)
TableLayoutPanel
Groupbox
However, I need to be able to account for new types of container being
present, so merely listing the types of container type of control is
not sufficient.
If the control passed to the method is a container control, then the
method calls itself recursively using the reference of the controls
within it.

Thanks again,

Greg.
Matt wrote:
Mythran wrote:
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Is there a simple way to test if a control is a container type control
(e.g. groupbox, panel etc)
>
I realise that all container controls have to by definition, have the
System.ComponentModel.DesignerAttribute. If there is an easy way to
query whether a control has this attribute, this may well be the way
forward. I'm not sure how to do this.
>
Or is there a different way?
>
Greg.
>
Although Matt's reply is true, you could check the instance in question to
see if it implements the IContainer interface.

I knew I should have taken the extra second to look at the interfaces.
Yours
is a much better answer. Honestly, though, I'm still not sure what
problem he
is trying to solve. Virtually every control implements IContainer.

Matt
Nov 16 '06 #5
Perhaps the easiest method for what I need is to look at the number of
controls within the control - if that is more than 0 then I need to
call the same code for each control within that control, and so on.

Greg.

Greg wrote:
Thanks Matt and Mythran.

I currently have a method that does some work on a control reference
passed to it. It needs to be understand whether the control passed to
it is capable of containing other controls - the current list being for
a winforms app:
FlowLayoutPanel
Panel
SplitContainer
TabControl (and tabpage)
TableLayoutPanel
Groupbox
However, I need to be able to account for new types of container being
present, so merely listing the types of container type of control is
not sufficient.
If the control passed to the method is a container control, then the
method calls itself recursively using the reference of the controls
within it.

Thanks again,

Greg.
Matt wrote:
Mythran wrote:
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Is there a simple way to test if a control is a container type control
(e.g. groupbox, panel etc)

I realise that all container controls have to by definition, have the
System.ComponentModel.DesignerAttribute. If there is an easy way to
query whether a control has this attribute, this may well be the way
forward. I'm not sure how to do this.

Or is there a different way?

Greg.

>
Although Matt's reply is true, you could check the instance in question to
see if it implements the IContainer interface.
I knew I should have taken the extra second to look at the interfaces.
Yours
is a much better answer. Honestly, though, I'm still not sure what
problem he
is trying to solve. Virtually every control implements IContainer.

Matt
Nov 16 '06 #6
That didn't work at all - some of the controls that I have created are
composite controls. Now I'm back to the drawing board - how to test a
control to see if it is a container type control.
Greg wrote:
Perhaps the easiest method for what I need is to look at the number of
controls within the control - if that is more than 0 then I need to
call the same code for each control within that control, and so on.

Greg.

Greg wrote:
Thanks Matt and Mythran.

I currently have a method that does some work on a control reference
passed to it. It needs to be understand whether the control passed to
it is capable of containing other controls - the current list being for
a winforms app:
FlowLayoutPanel
Panel
SplitContainer
TabControl (and tabpage)
TableLayoutPanel
Groupbox
However, I need to be able to account for new types of container being
present, so merely listing the types of container type of control is
not sufficient.
If the control passed to the method is a container control, then the
method calls itself recursively using the reference of the controls
within it.

Thanks again,

Greg.
Matt wrote:
Mythran wrote:
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Is there a simple way to test if a control is a container type control
(e.g. groupbox, panel etc)
>
I realise that all container controls have to by definition, have the
System.ComponentModel.DesignerAttribute. If there is an easy way to
query whether a control has this attribute, this may well be the way
forward. I'm not sure how to do this.
>
Or is there a different way?
>
Greg.
>

Although Matt's reply is true, you could check the instance in question to
see if it implements the IContainer interface.
>
I knew I should have taken the extra second to look at the interfaces.
Yours
is a much better answer. Honestly, though, I'm still not sure what
problem he
is trying to solve. Virtually every control implements IContainer.
>
Matt
Nov 16 '06 #7

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

Similar topics

2
by: Shabam | last post by:
I'm getting the following 2 errors randomly when doing a load test on a web application's search engine. As far as I know, there isn't writing to the DB involved when doing searches, so I'm at a...
0
by: ManjuG | last post by:
Hi, I have created an ActiveX control and build the project with 'No Common Language RunTime support' option and everything worked fine. But when I used the option 'Common Language Runtime Support...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
13
by: Moohoo | last post by:
I have two sorted containers, and I wish to know if any items from one container exist in the second container. Is there anything in the standard library to do this? Thanks
0
by: pabloazorin | last post by:
I developed a Date Picker web control using C# and .net framework 1.1 I added my control to Visual Studio 2003 IDE toolbar. When I drag and drop my control to design web page, the control renders...
1
by: --== Alain ==-- | last post by:
Hi, I have a huge problem... My property does not appear in the "propertyGrid" of "test Container", when i test my custom control. Here is the custom control code : namespace...
1
by: Doogie | last post by:
Hi, I have been trying to get a checkbox added to a repeater control of mine and then try to access events of the repeater control when a user clicks the checkbox. At first, since the control is...
0
by: DKn | last post by:
Hello All, I am having an ACtiveX Control developed in C#.Net 2.0 windows Control Library. I have tested this control.TCS through ACtiveX Control Test Container. It is working fine, But the...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.