473,396 Members | 1,847 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.

loop over the controls in my form

hi!
i have a class chooseLevel : Form
and i need to loop over all the radio buttons that are on my form, and
check their text. if their text is smaller than 4, i got to disable
them.
how do i do it?
thanx alot

Feb 22 '06 #1
6 1594
foreach (Control c in this.Controls)
{
RadioButton button = c as RadioButton;
if (button != null && button.Text.Length < 4)
{
button.Enabled = false;
}
}

Feb 22 '06 #2
it doesn't help.
i get in this.controls.count- 0
which means that although i put it on the form, it doesn't count it

Feb 22 '06 #3
oops sorry, i forgot to initialize the componnets. now it's fine
thanx

Feb 22 '06 #4
The sample posted will work, but only for controls that arent nested in other
controls (such as a groupbox, which is very common).

Here's an exercise I did some time ago that illustrates one technique for
"walking the control hierarchy" and identifying a control at any level:

http://www.eggheadcafe.com/articles/20040506.asp

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"be********@gmail.com" wrote:
hi!
i have a class chooseLevel : Form
and i need to loop over all the radio buttons that are on my form, and
check their text. if their text is smaller than 4, i got to disable
them.
how do i do it?
thanx alot

Feb 23 '06 #5
Thank you Peter.

Peter is right, particularly where radio buttons are concerned: they're
most often grouped within group boxes, and in that case my code snippet
won't find them.

Feb 23 '06 #6
Note that if panels etc get involved then you will need to recursively check
the .Controls of each Control - otherwise you will only look *directly* on
the form; e.g. (setting a tooltip in this case):

private void CascadeTooltip(Control control, string caption) {
toolTip.SetToolTip(control, caption);
foreach (Control subControl in control.Controls)
CascadeTooltip(subControl, caption);
}

Note that the form itself is a Control, so it can call CascadeTooltip(this,
"some value");

Marc
Feb 23 '06 #7

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

Similar topics

4
by: Ryan Liu | last post by:
How to loop though controls on the form? I set each control's TabStop and TabIndex, but at run time, I press Tab key, it jump though first control to last control and does not go back to the...
4
by: David A. Beck | last post by:
Is there a way I can loop through a form object in ASP.NET codebehind like in VB.NET and get all of the controls?
8
by: AFN | last post by:
I want to have a routine in a page base class that will take all the text fields on a web form, and then HtmlEncode their values. I'm having trouble figuring out if I want to loop controls or...
4
by: Ryan Ternier | last post by:
Thanks for the previous help guys! I got my list box issue working, but now i'm trying to loop through all the items in my page. I want to find each listbox, once I do i strip the ID down to...
33
by: Brian | last post by:
I have a list of plain HTML radio buttons that I want to be able to loop through, get the values from them and insert them into a db. each one should be a separate record... Can anyone please give...
8
by: dominique | last post by:
Hi, Is it possible (in vb.net with WinForms) to loop throw controls inside a container (form or panel) sorting the controls on a property (.tabindex for example) ? My problem : on several...
7
by: J L | last post by:
I need to loop through a form's controls collection and delete some based on type and location. I have tried For..Each and For i = 0 to form.controls.count - 1 but when I delete any it messes up...
1
by: Franck | last post by:
I'm looking at a way to loop throught all menuitem object of a form, including sub menu. From the form it self sub items doesn't matter because i can access them directly without having to pass by...
9
tlhintoq
by: tlhintoq | last post by:
Situation: A Windows Form with a single User Control containing 4 custom controls. This lets me drop the User Control on its own form to make it a dialog, or make it part of a larger configuration...
7
beacon
by: beacon | last post by:
Hi everybody, This may be an easy one, but I'm having a lot of trouble with it. I have a continuous form and I want to validate that the user has entered something in each of the required fields...
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: 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
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?
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
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
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...
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...

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.