如何从动态单选按钮获取价值

时间:2012-01-23 23:39:42

标签: vb.net select dynamic radio

我正在私人子中创建3个单选按钮,如:

For counter As Integer = 0 To rc - 1

    'controller name Radio button and properties.
    Dim dynRadio As New RadioButton()
    Me.Controls.Add(dynRadio)
    With dynRadio
       .Name = CStr(ds.Tables("MakeThisNameMeaningful").Rows(counter).Item(0))
       .Location = New Point(xAxis, yAxis)
       .TabStop = False
       .Text = CStr(ds.Tables("MakeThisNameMeaningful").Rows(counter).Item(0))
       .Width = 80
    End With

    yAxis = yAxis + 40
 Next

收音机拉好了。所以我有3个带有文本的无线电(从db中选择的结果)controller1,controller2,controller3

我有各种各样的故事,无法在谷歌上找到任何东西。哦,我应该提一下,我正试图从另一个私人子公司获得无线电值。我想按照以下方式做:

If controller1.Selected = true then
    'do stuff
End if

我知道上面的错误但不确定如何确定选择了哪个收音机:(

干杯, Ĵ

1 个答案:

答案 0 :(得分:1)

您可以遍历第二个私人子中的单选按钮。

Dim radios = Controls.OfType(Of RadioButton).AsQueryable()

For Each r As RadioButton In radios
    If r.Checked Then
      'this radio is checked. do something.
    End If
Next