473,387 Members | 1,619 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,387 software developers and data experts.

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.Controls" is the correct method to use, why don't a
get a count (8) of all the controls and is "this.Controls" 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 4025
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.Controls" is the correct method to use, why don't a
get a count (8) of all the controls and is "this.Controls" 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.Count 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.Controls.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.count

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
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...
5
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...
5
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);...
0
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...
7
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...
0
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...
4
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
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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,...

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.