How to get selected value of radio button in VB.NET

How to get the selected value of the radio button control in VB.NET. in this visual basic code example, Will create simple application that will display the value of selected radio buttons.

Get selected value of Radio Button in VB.NET

The Radio Button control is used to select one option from any number of choices that are given. If we want to select only one item from a group of items in the windows forms, we can use the radio button. Radio Button always represents that only one item is active and the remains are inactive in the form. In a simple way, it can hold any one value selected at a time.

We can use a Radio Button control in the VB.NET Windows follow the simple steps.

Step 1:

Open your visual studio > go to File menu > click on New project > and select language VB > and after naming the project > then click on Ok.

Step 2:

The Form1 will display on the screen now drag the Radio Button control from the toolbox and drop it on the Windows form.

Step 3:

we can set various properties of the RadioButton by clicking on it from the property window. Write the code on the form in code section .

Public Class RadioBtn
Private Sub RadioBtn_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text ="Form1"'Set the title of the form
Label1.Text="Select the Gender"
RadioButton1.Text="Male" 'Set the values
Button1.Text="Submit"'Set the button name
End Sub  
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim gen As String
RadioButton1.Checked = True Then
MsgBox(" Your gender is : " & gen) 
RadioButton2.Checked = True Then
MsgBox(" Your gender is : " & gen) 
MsgBox(" You have Selected the gender: " & gen)
End If
End Sub
End Class
Output screen:

As you can see in n the above example I have selected the second radio button whose value is Female so the MsgBox is showing the result as “your gender is Female”.

So in this way we can easily get the selected value of the Radio Button in VB.NET.