【问题标题】:Visual Basic - Grouped radio buttonsVisual Basic - 分组单选按钮
【发布时间】:2014-12-13 04:37:44
【问题描述】:

基本上我想要工作的是将所选单选按钮的文本插入到我已经拥有的 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 等

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

【问题讨论】:

标签: vb.net


【解决方案1】:

在一个 GroupBox 和一个 TextBox 中有两个 RadioButtons:

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 中,所以只需将文本放在你需要的地方。

【讨论】:

    猜你喜欢
    • 2012-04-23
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-23
    相关资源
    最近更新 更多