表单加载时检查设置单选按钮(vb net)?

时间:2016-11-22 03:33:02

标签: vb.net datagridview

我想以编程方式(在加载表单时)从不同的Group Box中选择一个RadioButton(只需要从所有单选按钮检查一个单选按钮)。

我将datagridview值加载到变量。 现在,我想选择与变量中的值对应的单选按钮。

我尝试使用else的简单代码if和select case。但两者都不起作用?

{ 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}

1 个答案:

答案 0 :(得分:0)

RadioButton1.Checked = True事件中设置Form_Shown

如果您正在设置选中的值,那么

Form_Load将无效。