user3236873 user3236873 - 1 year ago 94 Question

setting radio button checked when form loading (vb net)?

I want to select one of my RadioButton from a different Group Boxes (only one radio button needs to be check from all radio buttons) programmatically (when the form is loaded).

I'm loading datagridview value to a variable.
Now, I want to select the radio button corresponding to the value in the variable. .

I tried simple code using else if and select case. But both are not working?

{ Dim SpecimenName As String = frmMain.DataGridView1.Rows(0).Cells(4).Value.ToString
If SpecimenName = "" Then
ElseIf SpecimenName Like "Michanical" Then
ElseIf SpecimenName Like "Manage" Then
ElseIf SpecimenName Like "Civil" Then
RadioButton3.Checked = True
ElseIf SpecimenName Like "Electronics" Then
RadioButton4.Checked = True
ElseIf SpecimenName Like "Supply" Then
RadioButton5.Checked = True
ElseIf SpecimenName Like "Landscaping" Then
RadioButton6.Checked = True
ElseIf SpecimenName Like "P&D" Or SpecimenName Like "Project" Then
RadioButton7.Checked = True
End If}

Answer Source

Set RadioButton1.Checked = True in the Form_Shown event.

Form_Load will not work if that is where you are setting the checked values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download