user3236873 user3236873 - 11 days ago 6
Vb.net 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
'RadioButton1.AutoCheck()
ElseIf SpecimenName Like "Michanical" Then
RadioButton1.PerformClick()
ElseIf SpecimenName Like "Manage" Then
RadioButton2.PerformClick()
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

Set RadioButton1.Checked = True in the Form_Shown event.

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

Comments