Visual Basic - 分组单选按钮

时间:2014-10-17 14:50:37

标签: vb.net

基本上我想要工作的是将所选单选按钮的文本插入到我已经拥有的ListView中。

这是我的代码(Listview):

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles AddButton.Click
    Dim Col1 As String = ComboBox1.Text
    Dim Col2 As String = 
    Dim Col3 As String = ComboBox3.Text

    Dim order As New ListViewItem

    order.Text = Col1 'Adds to First column

    order.SubItems.Add(Col2) 'Adds to second column
    order.SubItems.Add(Col3) ' Adds to third column

    ListView1.Items.Add(order)

End Sub

如果我将RadioButton1.Text放入DIM Col2并在运行时选择它然后显示它但我希望它能找到选择了哪个单选按钮并显示正确的文本。我在GroupBox1组中有四个单选按钮,每个单选按钮是RadioButton1,2,3等

组合框的使用情况相同,但我的程序中需要某种单选按钮。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

在一个GroupBox中有两个RadioButtons,还有一个TextBox:

Private Sub RadioButtons_CheckedChanged(sender As Object, e As EventArgs) _
            Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
    If CType(sender, RadioButton).Checked Then
        Dim rButton As RadioButton =
            GroupBox1.Controls.
            OfType(Of RadioButton)().
            Where(Function(r) r.Checked = True).
            FirstOrDefault()
        Me.TextBox1.Text = CType(sender, RadioButton).Text
    End If
End Sub

单击RadioButton时,TextBox文本会更新。我不明白你想如何插入ListView,所以只需把文字放在你需要的地方。

相关问题