Results 1 to 4 of 4

Thread: Looping through controls

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Looping through controls

    Hello,

    I have this code that works for checking just one RadioButton to see if it is checked when looping through a group of RadioButtons. How can I check ALL of the RadioButtons?


    VB Code:
    1. foreach(Control EnumControl in this.Frame1.Controls)
    2. {
    3. if (EnumControl.GetType().Equals(typeof(RadioButton)))
    4. {
    5. if (optCommand0.Checked == true) //What do I do here to check ALL RadioButtons?
    6. {                  
    7. MessageBox.Show("I'm Here");
    8. break;
    9. }
    10. }
    11. }

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: Looping through controls

    Code:
    foreach(Control EnumControl in this.Frame1.Controls)
    {
      if (EnumControl.GetType().Equals(typeof(RadioButton))) 
      {
    	if (optCommand0.Checked == true)
    	{					
    	  MessageBox.Show("I'm Here");
    	  break;
    	}
      }
    }
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Re: Looping through controls

    My RadioButtons are:

    optCommand0
    optCommand1
    optCommand2.
    etc...

    In other words, I have many and would like to know how to loop through them without having to list each one. Sort of like optCommand(i).checked .

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Re: Looping through controls

    //Loops through controls in a Frame. Finds "checked" RadioButton and displays it's name.

    Code:
    foreach(Control ctrl in Frame1.Controls)
    {
          if(ctrl.GetType() == typeof(RadioButton))
         {					
              if(((RadioButton)ctrl).Checked == true)		
              {
                    MessageBox.Show(ctrl.name);
              } 
         }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width