locked
How to get a value from a radio button

    Question

  • I have several text boxes and two radio buttons to gather data to a listbox. Now I don't know how to get a value from a radio button to insert in a list box. Can someone give a little help.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            If TextBox5.Text = "" Then
                Dim Aviso As DialogResult
                Aviso = MessageBox.Show("Reveja os valores dados às tensões. Pretende continuar?", "MecMat", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
            End If

            Dim newItm As ListViewItem
            Dim Str(13) As String

            Str(0) = TextBox1.Text.ToString()
            Str(1) = TextBox2.Text.ToString()
            Str(2) = TextBox3.Text.ToString()
            Str(3) = TextBox4.Text.ToString()
            Str(4) = TextBox5.Text.ToString()
            Str(5) = TextBox6.Text.ToString()
            Str(6) = TextBox7.Text.ToString()
            Str(7) = TextBox8.Text.ToString()
            Str(8) = TextBox9.Text.ToString()
            Str(9) = TextBox10.Text.ToString()
            Str(10) = TextBox11.Text.ToString()
            Str(11) = TextBox12.Text.ToString()
            Str(12) = TextBox13.Text.ToString()
            Str(13) = RadioButton1.Text.ToString() ???????????


            newItm = New ListViewItem(Str)
            ListView1.Items.Add(newItm)

            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox5.Text = ""
            TextBox6.Text = ""
            TextBox7.Text = ""
            TextBox8.Text = ""
            TextBox9.Text = ""
            TextBox10.Text = ""
            TextBox11.Text = ""
            TextBox12.Text = ""
            TextBox13.Text = ""

        End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

        End Sub
    Tuesday, April 10, 2007 3:26 PM

Answers

  • Thanks anyway I've managed to do it.

    If RadioButton1.Checked Then
                Str(13) = RadioButton1.Text.ToString()
            Else
                Str(13) = RadioButton2.Text.ToString()
            End If
    Tuesday, April 10, 2007 7:57 PM

All replies

  • Either you're asking for the label of the control, which can be returned as a string via:

     

    Code Snippet
    RadioButton1.Text

     

     

    Or you are asking for the boolean value of the control indicating if it is selected or not, via:

     

    Code Snippet

    RadioButton1.Checked

     

    Str(13)= RadioButton1.Checked

     

    Tuesday, April 10, 2007 4:31 PM
  • The problem is that I need both. I need the value returned by the checked radio button. By the way how do I define it?
    Tuesday, April 10, 2007 6:15 PM
  • Thanks anyway I've managed to do it.

    If RadioButton1.Checked Then
                Str(13) = RadioButton1.Text.ToString()
            Else
                Str(13) = RadioButton2.Text.ToString()
            End If
    Tuesday, April 10, 2007 7:57 PM