1

Basically what i'm wanting to work is for the text of the selected radio button to be inserted into a ListView that i already have.

Here is my code (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

If i put RadioButton1.Text In DIM Col2 and select it when it runs then it displays it but i would like it so that it finds out which radio button is selected and displays the correct text. I Have four radio buttons all in a group called GroupBox1 and each radio button is RadioButton1, 2, 3 etc

The Combo boxes are getting used as the same but i need some sort of radio button in my program. Any help is appreciated.

1 Answers1

0

With two RadioButtons inside one GroupBox, and one 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

When a RadioButton is clicked, the TextBox text gets updated. I don't understand how you want to insert into the ListView, so just take the text and put it where you need it.

djv
  • 15,168
  • 7
  • 48
  • 72