2014-10-17 29 views
1

基本上我想要工作的是所选单选按钮的文本插入到已有的ListView中。Visual Basic - 分组单选按钮

这里是我的代码(列表视图):

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在昏暗col2的,并选择它时,它运行则显示,但这样它找出哪些无线我想它按钮被选中并显示正确的文本。我有一个名为GroupBox1的组中的四个单选按钮,每个单选按钮都是RadioButton1,2,3等。

组合框的用法相同,但我需要某种单选按钮。任何帮助表示赞赏。

+0

设置为“DropDownList”的组合框与RB组的设置完全相同,但您不必遍历任何内容以查找哪个按下的按钮 – Plutonix 2014-10-17 14:53:21

+0

[如何获取组合框中的选中单选按钮? ](http://stackoverflow.com/questions/6466952/how-to-get-a-checked-radio-button-in-a-groupbox) – Plutonix 2014-10-17 14:59:55

回答

0

有了一个分组框内部的两个单选按钮,并了一个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 

当点击一个单选按钮,文本框的文本得到更新。我不明白你想如何插入到ListView中,所以只需把文本放在需要它的地方。