473,762 Members | 6,675 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List of Controls on a form

Hi

In a Windows forms application I have 2 forms A and B; Form B inherits from
form A. Form A is never displayed and its only purpose is to be inherited
from and therefore contains mostly public/protected methods that I have
created (as well a few controls that inheriting forms may use). In my method
on form A (public virtual void setcontrols()) I need a list of all controls
on the instantiated form (in this example form B). Form B has a Menu (with 5
MenuItems), an inherited Panel and Button and an additional Button. Help
seems to indicate that "this.Controls. Count" should return an integer count
of all the controls on the instantiated form B. "this.Controls. Count" returns
the actual int value of 1 rather than 8 (which is what I expect).

On the basis that "this.Contr ols" is the correct method to use, why don't a
get a count (8) of all the controls and is "this.Contr ols" the correct method
to use anyway? If this is not the correct method then what is the correct
method?

Thanks in advance.
Nov 16 '05 #1
3 4048
OK

Nov 16 '05 #2
On Mon, 21 Mar 2005 03:17:01 -0800, Roger wrote:
Hi

In a Windows forms application I have 2 forms A and B; Form B inherits from
form A. Form A is never displayed and its only purpose is to be inherited
from and therefore contains mostly public/protected methods that I have
created (as well a few controls that inheriting forms may use). In my method
on form A (public virtual void setcontrols()) I need a list of all controls
on the instantiated form (in this example form B). Form B has a Menu (with 5
MenuItems), an inherited Panel and Button and an additional Button. Help
seems to indicate that "this.Controls. Count" should return an integer count
of all the controls on the instantiated form B. "this.Controls. Count" returns
the actual int value of 1 rather than 8 (which is what I expect).

On the basis that "this.Contr ols" is the correct method to use, why don't a
get a count (8) of all the controls and is "this.Contr ols" the correct method
to use anyway? If this is not the correct method then what is the correct
method?

Thanks in advance.


Hmm... Do you have a panel (or a group box) as the main control in your
form A? And the other controls are placed inside this panel?

If so, with this.Controls.C ount you only get the panel. Because the other
controls are not inside your form, but inside the panel.

So to get the number of controls, I think you have to do something like
this:

int count = this.mypanel.Co ntrols.Count; or
int count = this.mygroupbox .Controls.Count ;

But again, if inside your panel are sub panels or group boxes, such a sub
panel again is just counted with 1. The controls inside the subpanel are
not counted. If you need them as well, you have to go recursive thur all
controls of your form and for each control you have to go thru its child
controls and so on.

hth.
--
Claudio Grazioli
http://www.grazioli.ch
Nov 16 '05 #3
Roger,

The controls in your base form are probably declared as private, when that
would be public, you could use them as

base.mycontrol
You will always see them as
base.controls.c ount

I hope this helps,

Cor
Nov 16 '05 #4

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

Similar topics

1
2793
by: Georg Scholz | last post by:
Hello, The class "Control" contains a documented Property "ControlType". So for example, in a form, you can write code like this: Dim c as control set c = me.Controls("textbox1") if c.ControlType = acTextBox then ...
5
11458
by: Kay | last post by:
Hello, I have two list boxes on my form, one initially displays with items and the other displays blank, by clicking a button, it is possible to move items from one box to another and vice a versa, this works fine. I also have a dropdown list on the page with autopost back = true, my problem is as follows: when the user selects an option in the dropdown list the form is posted back to the server and certain other processing happens, then...
5
4230
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1); System.Data.SqlClient.SqlCommand dbCommand1 = new System.Data.SqlClient.SqlCommand();
0
3240
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another way... here is my code on how I did it to help anyone starting out get an idea of how to use virtual mode in ..NET 2.0 Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared
7
6217
by: Mark | last post by:
Hello. I am developing an Access 2000 form, and I want to populate a databound list box using a saved query that requires parameters. Is there any way to do this? I tried creating a DAO querydef object and setting the parameters, and then assigned the querydef object to the list box "rowsource" property. This did not work. Thanks -Mark
0
2911
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string strDataValueField; string strDataTextField; public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
4
13361
by: Toze | last post by:
I'm using a assembly to load my apllication (ex: Mobi.exe), and now I need to list all forms in my apllication and list all controls (ex: txtname;btnname) inside of each form.
5
5021
by: nktt3514 | last post by:
I'm using a assembly to load my apllication, and now I need to list all forms in my apllication and list all controls. I have read the topic on http://bytes.com/topic/c-sharp/answers/545315-list-all-controls-inside-each-form and do like that, i only listed all form's name but i can't listed any control in any form. When i used the CreatInstance function to get the controls of the form, it always return null value. Please help me!
0
9377
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
10136
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...
1
9925
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
9811
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
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
6640
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.