473,387 Members | 1,812 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.

iterating through radio button collection as an array

I know you can iterate through a collection of radio buttons in a
panel, using a "for each in control" type iteration that c# supports,
but is it possible to iterate through the radio buttons collection, as
if they were an array of radio buttons ?

Basically i want to plonk the radio buttons on a panel then use a for
loop to index through the radio buttons with an idenex to check thier
state.

I want to do it this way becasue i want to make use of the index
integer when i find the checked radio button in the control group
thanks

Peted
Feb 16 '07 #1
5 13121
PS

<Petedwrote in message news:5n********************************@4ax.com...
>I know you can iterate through a collection of radio buttons in a
panel, using a "for each in control" type iteration that c# supports,
but is it possible to iterate through the radio buttons collection, as
if they were an array of radio buttons ?
You will have to cast them to RadioButton

foreach(Control c in myRadioButtonsContainer.Controls)
{

// whatever style you prefer for the casting / check

if(c is RadioButton)
{
RadioButton rb = (RadioButton)c;
}

RadioButton rb = c as RadioButton;
if(rb != null)
{

}
}

PS
>
Basically i want to plonk the radio buttons on a panel then use a for
loop to index through the radio buttons with an idenex to check thier
state.

I want to do it this way becasue i want to make use of the index
integer when i find the checked radio button in the control group
thanks

Peted

Feb 16 '07 #2
Hello, thanks for th reply

i know it can be done that way, but as i said i want to know if it is
possible to iterate through those same controls without using the
"foreach" command.

i want to iterate using a for loop as if the rb controls were an array
with a and index

eg

for (int i =0; i<number of radiobuttons;i++)
radiobutton[i].checked

etc etc etc

thanks

Peted

On Fri, 16 Feb 2007 14:48:13 GMT, "PS" <ec***********@hotmail.com>
wrote:
>
<Petedwrote in message news:5n********************************@4ax.com...
>>I know you can iterate through a collection of radio buttons in a
panel, using a "for each in control" type iteration that c# supports,
but is it possible to iterate through the radio buttons collection, as
if they were an array of radio buttons ?

You will have to cast them to RadioButton

foreach(Control c in myRadioButtonsContainer.Controls)
{

// whatever style you prefer for the casting / check

if(c is RadioButton)
{
RadioButton rb = (RadioButton)c;
}

RadioButton rb = c as RadioButton;
if(rb != null)
{

}
}

PS
>>
Basically i want to plonk the radio buttons on a panel then use a for
loop to index through the radio buttons with an idenex to check thier
state.

I want to do it this way becasue i want to make use of the index
integer when i find the checked radio button in the control group
thanks

Peted
Feb 17 '07 #3
PS

<Petedwrote in message news:2l********************************@4ax.com...
Hello, thanks for th reply

i know it can be done that way, but as i said i want to know if it is
possible to iterate through those same controls without using the
"foreach" command.

i want to iterate using a for loop as if the rb controls were an array
with a and index

eg

for (int i =0; i<number of radiobuttons;i++)
radiobutton[i].checked

etc etc etc
you can access with the indexer like
((RadionButton)myRadioButtonsContainer.Controls[3]).Checked

PS
>
thanks

Peted

On Fri, 16 Feb 2007 14:48:13 GMT, "PS" <ec***********@hotmail.com>
wrote:
>>
<Petedwrote in message
news:5n********************************@4ax.com. ..
>>>I know you can iterate through a collection of radio buttons in a
panel, using a "for each in control" type iteration that c# supports,
but is it possible to iterate through the radio buttons collection, as
if they were an array of radio buttons ?

You will have to cast them to RadioButton

foreach(Control c in myRadioButtonsContainer.Controls)
{

// whatever style you prefer for the casting / check

if(c is RadioButton)
{
RadioButton rb = (RadioButton)c;
}

RadioButton rb = c as RadioButton;
if(rb != null)
{

}
}

PS
>>>
Basically i want to plonk the radio buttons on a panel then use a for
loop to index through the radio buttons with an idenex to check thier
state.

I want to do it this way becasue i want to make use of the index
integer when i find the checked radio button in the control group
thanks

Peted

Feb 17 '07 #4
If I were you, I would maintain my own array of radio buttons as a
separate structure, and then iterate over that.

If you want the index to have meaning, then you'll have to build the
array in code, yourself.

If it doesn't matter which index corresponds to which button, you
could build it once, in the constructor of your form, and then just
use it from then on:

ArrayList radioButtons = new ArrayList();
foreach (Control ctl in this.Controls)
{
RadioButton btn = ctl as RadioButton;
if (btn != null) radioButtons.Add(btn);
}
this._radioButtonArray =
(RadioButton[])radioButtons.ToArray(typeof(RadioButton));

On Feb 16, 6:25 pm, Peted wrote:
Hello, thanks for th reply

i know it can be done that way, but as i said i want to know if it is
possible to iterate through those same controls without using the
"foreach" command.

i want to iterate using a for loop as if the rb controls were an array
with a and index

eg

for (int i =0; i<number of radiobuttons;i++)
radiobutton[i].checked

etc etc etc

thanks

Peted

On Fri, 16 Feb 2007 14:48:13 GMT, "PS" <ecneserpeg...@hotmail.com>
wrote:


<Petedwrote in messagenews:5n********************************@4ax .com...
>I know you can iterate through a collection of radio buttons in a
panel, using a "for each in control" type iteration that c# supports,
but is it possible to iterate through the radio buttons collection, as
if they were an array of radio buttons ?
You will have to cast them to RadioButton
foreach(Control c in myRadioButtonsContainer.Controls)
{
// whatever style you prefer for the casting / check
if(c is RadioButton)
{
RadioButton rb = (RadioButton)c;
}
RadioButton rb = c as RadioButton;
if(rb != null)
{
}
}
PS
Basically i want to plonk the radio buttons on a panel then use a for
loop to index through the radio buttons with an idenex to check thier
state.
I want to do it this way becasue i want to make use of the index
integer when i find the checked radio button in the control group
Feb 18 '07 #5
thanks for that
On Sat, 17 Feb 2007 20:07:05 GMT, "PS" <ec***********@hotmail.com>
wrote:
>
<Petedwrote in message news:2l********************************@4ax.com...
>Hello, thanks for th reply

i know it can be done that way, but as i said i want to know if it is
possible to iterate through those same controls without using the
"foreach" command.

i want to iterate using a for loop as if the rb controls were an array
with a and index

eg

for (int i =0; i<number of radiobuttons;i++)
radiobutton[i].checked

etc etc etc

you can access with the indexer like
((RadionButton)myRadioButtonsContainer.Controls[3]).Checked

PS
>>
thanks

Peted

On Fri, 16 Feb 2007 14:48:13 GMT, "PS" <ec***********@hotmail.com>
wrote:
>>>
<Petedwrote in message
news:5n********************************@4ax.com ...
I know you can iterate through a collection of radio buttons in a
panel, using a "for each in control" type iteration that c# supports,
but is it possible to iterate through the radio buttons collection, as
if they were an array of radio buttons ?

You will have to cast them to RadioButton

foreach(Control c in myRadioButtonsContainer.Controls)
{

// whatever style you prefer for the casting / check

if(c is RadioButton)
{
RadioButton rb = (RadioButton)c;
}

RadioButton rb = c as RadioButton;
if(rb != null)
{

}
}

PS
Basically i want to plonk the radio buttons on a panel then use a for
loop to index through the radio buttons with an idenex to check thier
state.

I want to do it this way becasue i want to make use of the index
integer when i find the checked radio button in the control group
thanks

Peted
Feb 18 '07 #6

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

Similar topics

3
by: chuck | last post by:
Hi, This is a test for a larger form i am working on. I want to have a real time display of the radio button value when selected. I tried with various event handlers with varying success. The...
3
by: Amelyan | last post by:
When we want radio button to belong to a group name we say, radio1.GroupName="GroupA". In this case, radio1 will be unselected if another radio button is selected in "GroupA". Is there a way...
2
by: Patrick | last post by:
Hello - I'm working on a VB program that uses two radio button collections - one of State, the other of Capitols. If the state is selected in collection1, then the appropriate capitol is selected...
4
by: crystal | last post by:
Hi, I have a radio button group with 2 elements. Can I use javascript to remove the last element based on user's input? Thanks.
1
by: s.chelliah | last post by:
Hi, I am trying to use javascript, div tag and radio button to disable/enable a text box. It works fine in netscape and firefox, but in IE, the text box is not disabled when the user checks the...
9
by: wreed | last post by:
I have a for loop seen below.... var the_form = document.getElementById(formName); for(var i=0; i<the_form.length; i++) { var temp = the_form.elements.type; if (temp == "radio") { for (x =...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
2
by: Eric Layman | last post by:
Hi, I have a radio button and a combo box. Upon changing a value for radio button, the combo box values will be dynamically updated. I have an idea on how to go abt doing it but Im stuck...
5
by: mad.scientist.jr | last post by:
According to http://www.quirksmode.org/js/forms.html you need to look through a radio button's members to find the value: I tried writing a reusable function to return the value, see code at:...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
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
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,...

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.