如果对radiobutton的声明

时间:2016-06-13 10:35:23

标签: vb.net checkbox radio-button

所以我有4个radiobutton,其中3个将使用checkbox中的相同项目,但另一个将在检查后向用户显示其他信息。这是我正在使用的代码:

If rbPorData.Checked And rbPorExtensão.Checked And rbPorNome.Checked Then
        ShowInfoComboBox()
    ElseIf rbPcName.Checked Then
        ShowInfoComboBoxPcName()
End If

这是我所称的其中一种方法的代码:

Private Sub ShowInfoComboBoxPcName()
        SQLCon = New SqlConnection
        SQLCon.ConnectionString = "........................"
        Try
            SQLCon.Open()
            Query = "SELECT PcName AS [NomePc]
                    FROM infofile 
                    GROUP BY PcName"
            SqlCmd = New SqlCommand(Query, SQLCon)
            SqlDR = SqlCmd.ExecuteReader
            While SqlDR.Read
                Dim pcName = SqlDR.GetString(0)
                cbExtensão.Items.Add(pcName)
            End While
            SQLCon.Close()
        Catch ex As SqlException
            MsgBox(ex.Message)
        Finally
            SQLCon.Dispose()
        End Try
    End Sub

我应该在哪里使用此代码才能使其正常工作?我已经做了一些尝试来完成这项工作,其中一个是将if语句放入表单中,但它不起作用,因为我正在使用制表符。

1 个答案:

答案 0 :(得分:0)

您需要使用.Net'CheckChanged'事件:https://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton.checkedchanged(v=vs.110).aspx

Private Sub rd_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbPorData.CheckedChanged, rbPorExtensão.CheckedChanged, rbPorNome.CheckedChanged, rbPcName.CheckedChanged
    If rbPorData.Checked OrElse rbPorExtensão.Checked OrElse rbPorNome.Checked Then
        ShowInfoComboBox()
    ElseIf rbPcName.Checked Then
        ShowInfoComboBoxPcName()
    End If
End Sub