2014-03-13 60 views
1

我正在創建基於電子郵件計數的單選按鈕,當表單打開時,用戶將檢查單選按鈕,然後該emailId動態存儲在配置文件中。前景添加在如何在vb.net中動態檢查單選按鈕

當outlook將關閉,並再次打開,然後我從Config文件中獲取最後選擇的郵件ID並存儲在字符串中,但我無法檢查該特定的emailID我從配置中獲取,因爲單選按鈕我已經動態創建。每當表格將打開我想檢查最後選定的radioButton,即使我關閉了前景也一次又一次我打開我需要檢查最後選定的單選按鈕。

這是我的動態創建的單選按鈕

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 

這種方法,我在Form_Load事件

調用這是在配置文件

覈對,對於我的按鈕的Click事件代碼,電子郵件ID檢查和更新
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 
+0

你想在哪裏檢查單選按鈕? – Sathish

回答

1

假設你有一個變量更新的電子郵件ID字符串,說selectedEmailIdFromConfig

然後在下面您的代碼段看起來應該是這樣

For Each email As String In Arremailslist 
      Dim rb As New RadioButton 
      rb.Name = email 
      rb.Text = email 
      rb.AutoSize = True 

      'Check the radiobutton by string equality check 
      If selectedEmailIdFromConfig = email Then 
       rb.Checked = True 
      End If 


      dynamictablelayout.SetColumn(rb, 0) 
      dynamictablelayout.SetRow(rb, i) 
      dynamictablelayout.Controls.Add(rb) 
      i = i + 1 
     Next 

我希望這有助於。

+0

Thanku @Karti,它的工作就像我想要的那樣。 – Saurabh