473,405 Members | 2,373 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,405 software developers and data experts.

Get all existing object of a form...

PL
I try to find a way to get all the existing objects related to a WinForm...

I tried "this.Controls" and "this.components.Components" but I'm not
reaching all the existing objects...

I need to loop across all objects to verify the content of their "tag"
property and modify their "text" or "caption" property depending of the
object type and "tag" property value.

Thanks.
--
PL
Jul 6 '06 #1
5 2262
PL wrote:
I try to find a way to get all the existing objects related to a
WinForm...

I tried "this.Controls" and "this.components.Components" but I'm not
reaching all the existing objects...

I need to loop across all objects to verify the content of their "tag"
property and modify their "text" or "caption" property depending of the
object type and "tag" property value.

Thanks.
Hi PL,

You're probably not getting them all, because some controls can contain
other controls. You need to recurse over all the controls like this:

///
private void RecurseControls ( Control baseControl )
{
foreach ( Control ctrl in baseControl.Controls )
{
// Process your control here.
RecurseControls( ctrl );
}
}
///

Then, to run the recursive algorithm, do this:

///
RecurseControls( this );
///

In the context of your form.

--
Hope this helps,
Tom Spink
Jul 6 '06 #2
PL
Hi Tom,

I'm using exactly the same algorithm and I still don't see all the objects...
I noticed that I have this problem espacially with MenuItem (from MainMenu).
I know that it doesn't have any "tag" property associated to them, but
anyway, I'm not seeing the MenuItem object while looping so...

Thanks

--
PL
"Tom Spink" wrote:
PL wrote:
I try to find a way to get all the existing objects related to a
WinForm...

I tried "this.Controls" and "this.components.Components" but I'm not
reaching all the existing objects...

I need to loop across all objects to verify the content of their "tag"
property and modify their "text" or "caption" property depending of the
object type and "tag" property value.

Thanks.

Hi PL,

You're probably not getting them all, because some controls can contain
other controls. You need to recurse over all the controls like this:

///
private void RecurseControls ( Control baseControl )
{
foreach ( Control ctrl in baseControl.Controls )
{
// Process your control here.
RecurseControls( ctrl );
}
}
///

Then, to run the recursive algorithm, do this:

///
RecurseControls( this );
///

In the context of your form.

--
Hope this helps,
Tom Spink
Jul 6 '06 #3
PL wrote:
Hi Tom,

I'm using exactly the same algorithm and I still don't see all the
objects... I noticed that I have this problem espacially with MenuItem
(from MainMenu). I know that it doesn't have any "tag" property associated
to them, but anyway, I'm not seeing the MenuItem object while looping
so...

Thanks
Hi PL,

The reason for this is that MenuItems aren't contained within the Controls
collection of their parent. They are contained within the Items
collection, a property of the MenuItem. You'll have to make a special case
for this, and other controls that implement subcontrols by means of
an 'Items' collection.

The main reason for this is that a MenuItem is not a control, so it doesn't
make sense, to keep it in the Controls collection. Not only that, since a
MenuItem isn't a control, it won't "fit" in the Controls collection,
because it doesn't derive from Control.

--
Hope this helps,
Tom Spink
Jul 6 '06 #4
PL
Thanks for your answers Tom

I would have though that it would have a particular collection allowing us
to view all existing objects in an application... It appears not.
--
PL
"Tom Spink" wrote:
PL wrote:
Hi Tom,

I'm using exactly the same algorithm and I still don't see all the
objects... I noticed that I have this problem espacially with MenuItem
(from MainMenu). I know that it doesn't have any "tag" property associated
to them, but anyway, I'm not seeing the MenuItem object while looping
so...

Thanks

Hi PL,

The reason for this is that MenuItems aren't contained within the Controls
collection of their parent. They are contained within the Items
collection, a property of the MenuItem. You'll have to make a special case
for this, and other controls that implement subcontrols by means of
an 'Items' collection.

The main reason for this is that a MenuItem is not a control, so it doesn't
make sense, to keep it in the Controls collection. Not only that, since a
MenuItem isn't a control, it won't "fit" in the Controls collection,
because it doesn't derive from Control.

--
Hope this helps,
Tom Spink
Jul 6 '06 #5
PL
I noticed that almost all objects are listed under "this" (I see that at
debug time with QuickWatch), is there a way to access it? For now, I'm only
able to access the form, it would be nice to have access to all the others.

Thanks
--
PL
"Tom Spink" wrote:
PL wrote:
Hi Tom,

I'm using exactly the same algorithm and I still don't see all the
objects... I noticed that I have this problem espacially with MenuItem
(from MainMenu). I know that it doesn't have any "tag" property associated
to them, but anyway, I'm not seeing the MenuItem object while looping
so...

Thanks

Hi PL,

The reason for this is that MenuItems aren't contained within the Controls
collection of their parent. They are contained within the Items
collection, a property of the MenuItem. You'll have to make a special case
for this, and other controls that implement subcontrols by means of
an 'Items' collection.

The main reason for this is that a MenuItem is not a control, so it doesn't
make sense, to keep it in the Controls collection. Not only that, since a
MenuItem isn't a control, it won't "fit" in the Controls collection,
because it doesn't derive from Control.

--
Hope this helps,
Tom Spink
Jul 6 '06 #6

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

Similar topics

7
by: Andy Bates | last post by:
I have hopefully a simple problem in C#. I designed a form with a listview on left, vert splitter against that, then the remainder of the form from top to bottom: a listview, horiz splitter and...
2
by: Mark Perona | last post by:
I created an ASP.net form with an editable datagrid on it. I can create new records, and update and delete existing records. The problem I have is that I want a field in the grid to be editible...
3
by: Chris Bingham | last post by:
Hi, I'm learning VB.Net at the moment, and while I'm doing it I'm writing a couple of programs for work! They all work with the same Access Database, but I'm having a problem with modifying...
1
by: Christopher W. Douglas | last post by:
I am building a VB.NET application in Visual Studio.NET 2003. I have an existing project with code and forms I want to reuse in this project. If I am copying a module file, then Add Existing Item...
0
by: Mike | last post by:
VB .NET 2003, Pocket PC 2003, CF 1.0 SP 2 Only when I use a proxy server, I'm getting this error when attempting to write data to a Stream object from an HTTPWebRequest object....
1
by: Paul Bromley | last post by:
Please help with this one - I have scoured the newsgroups for information on this, and all of the responses relate to how to refernce controls on a NEW instanc of a form and not an exitsing one. I...
4
by: CodeLeon | last post by:
I am designing an enhanced GUI suite, and i need to know how to: * Make a user control a "helper" control, ie, one that sits at the bottom (like timer or process) * Make this control modify the...
9
by: jdlists | last post by:
I have inheirted some existing code, that i will explain in a moment, have needed to extend and ultimately should be able to run in threads. I've done a bunch of work with python but very little...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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,...
0
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...

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.