for next loop with RadioButton...

dtvonly

Member
Joined
Jan 3, 2013
Messages
22
Programming Experience
5-10
Hi. This is what I have now:

VB.NET:
if RadioButton1.Checked then
    textbox1.text = "button1 checked"
else
    textbox1.text = "button1 not checked"

if RadioButton2.Checked then
    textbox1.text = "button2 checked"
else
    textbox1.text = "button2 not checked"


Is there another way of checking the Radiobutton(i).checked where i is in the for next loop?
VB.NET:
for (i=1 to 2)
   if (RadioButton(i).checked) then
      textbox1.text = "button" & i &" checked"
   else  
      textbox1.text = "button" & i &" not checked"
next i

Please advise. Thank you.
 
Controls collection is indexable, each container (including form) has such collection. You may also create your own array/list that you can index if that is more suitable.
If you have other controls also in same collection you can use the OfType Linq filter to first get only the radiobuttons, convert ToArray and index that.
 
Back
Top