2014-10-17 42 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中,所以只需把文本放在需要它的地方。