title: How to checked Radio Button dynamically in vb.net
body: <p>I am creating radioButton based on the email count when form will open and user will checked the radio Button then that emailId i am storing in config file dynamically.This functionality I am implementing in outlook add in</p>
  
  <p>when outlook will closed and again it will open then i am getting that last selected mail ID from Config file and storing in string but i am not able to checked that particular emailID those i get from config because radiobutton i have created dynamically.when every time form will open i want to checked last selected radioButton even if i closed the outlook also and again i open i need to check last selected Radio Button.</p>
  
  <p>This is my dynamically created radio buttons</p>
  
  <pre><code>    For Each email As String In Arremailslist
          Dim rb As New RadioButton
          rb.Name = email
          rb.Text = email
          rb.AutoSize = True
  
          dynamictablelayout.SetColumn(rb, 0)
          dynamictablelayout.SetRow(rb, i)
          dynamictablelayout.Controls.Add(rb)
          i = i + 1
      Next
  </code></pre>
  
  <p>and this method i am calling in Form_Load Event </p>
  
  <p>This is my Button click event code for checking which email ID checked and updating in config file</p>
  
  <pre><code>Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
      selectedmailID = Nothing
      For Each c As Control In dynamictablelayout.Controls
          If c.GetType Is GetType(RadioButton) Then
              Dim rb As RadioButton = DirectCast(c, RadioButton)
              If rb.Checked Then
                  selectedmailID = rb.Text
                  updateconfige(selectedmailID)
                  Exit For
              End If
          End If
      Next
      Me.Close()
  End Sub
  </code></pre>