title: Unchecking all RadioButtons in a For Each Control loop
body: <p>I've got 7 <code>RadioButtons</code> on my form, 5 in one group, 2 in another. When they were in <code>GroupBoxes</code>, checking one of the <code>RadioButtons</code> didn't uncheck the other ones in the same <code>GroupBox</code>, for some reason - I think because the <code>AutoCheck</code> value was set to <code>False</code>, which it had to be because otherwise when the form loaded, one of the <code>RadioButtons</code> would be checked by default, and I don't want this to happen.</p>
  
  <p>So, to uncheck the other <code>RadioButtons</code> within the same <code>GroupBox</code>, I'm trying to write a subroutine which is called, after setting the value to <code>True</code> in the <code>RadioButton_Click</code> event.</p>
  
  <pre><code>For Each c As Control In Me.Controls
        If TypeOf c Is RadioButton Then
            If c.Name &lt;&gt; "rbtnAllSuppliers" AndAlso c.Name &lt;&gt; "rbtnIndividual" Then
                If c.Name &lt;&gt; rbtn.Name Then
                    For Each rbt As RadioButton In Me.Controls
                        If rbt.Name = c.Name Then
                            rbt.Checked = False
                        End If
                    Next
                End If
            End If
        End If
  Next
  </code></pre>
  
  <p>This code moreorless works. For each control on the form, if it's a <code>RadioButton</code> which isn't called <code>rbtnAllSuppliers</code> or <code>rbtnIndividual</code> (The 2 seperate <code>RadioButtons</code>, and it's not the <code>RadioButton</code> that is being set to <code>True</code>, then set it to <code>False</code>.</p>
  
  <p>The issue being, it is counting the 2 <code>Labels</code> as <code>RadioButtons</code>, or at least casting them to be so, so it errors when trying to set a ``Checked<code>value of the</code>Label`.</p>
  
  <p>I then tried something similar </p>
  
  <pre><code>For Each c As Control In Me.Controls
          If c.GetType Is GetType(RadioButton) Then
              If c.Name &lt;&gt; "rbtnAllSuppliers" AndAlso c.Name &lt;&gt; "rbtnIndividual" Then
                  If c.Name &lt;&gt; rbtn.Name Then
                      AddHandler DirectCast(c, RadioButton).Checked, AddressOf c.
                  End If
              End If
          End If
      Next
  </code></pre>
  
  <p>But I'm not sure what I would put for the <code>AddressOf</code> code? What would go in here as the delegate? If I put <code>AddressOf currentSubroutine()</code>, surely an infinite loop will be created?</p>
  
  <p>Is there a way to uncheck all <code>RadioButtons</code> using a similar method that I'm not aware of?</p>
  
  <p>What's the best way to go about achieving this?</p>