检查tabcontrol中非活动选项卡上的组合框

时间:2014-12-12 17:43:26

标签: vb.net

我需要能够在选项卡控件中检查组合框的选择项是否选中了选项卡。

目前我正在根据组合框是否可见来进行,但这只会检查所选标签的组合。

有没有办法可以在“非活动”标签上获得组合框的选择项?

每个标签都有一个tablelayoutpanel,其中包含有问题的组合框,但如上所述,cbo.visible仅适用于当前选定的标签。

Private Function checkAnswers(ByVal table As TableLayoutPanel, ByVal ResponseKey As String) As Boolean
    Dim allAnswered As Boolean = True
    Dim s As String = ""
    For Each c As Control In table.Controls

        If c.GetType() Is GetType(Label) Then
            Dim lbl As Label = CType(c, Label)
            s = lbl.Text
        End If

        If TypeOf c Is ComboBox Then
            Dim cbo As ComboBox = c
            If Responses(ResponseKey)(s) = "NotAnswered" And cbo.Visible = True Then 'Combobox is showing and isnt answered
                allAnswered = False
            End If
        End If
    Next
    Return allAnswered
End Function

- EDIT-- 调用checkAnswers的方法:

Private Sub SubmitAnswers(ByRef tab As TabPage, ByRef table As TableLayoutPanel, ByRef ResponseKey As String)

    Dim instAnswer As CaisseAnswerBU = New CaisseAnswerBU

    Dim allAnswered As Boolean = True

    If Not checkAnswers(table, ResponseKey) AndAlso isEndofQuestions = True Then
        allAnswered = False
        MessageBox.Show("You must give an answer for all of " & tab.Text & "'s questions", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    ElseIf checkAnswers(table, ResponseKey) AndAlso isEndofQuestions = True Then

        counter = 0

        For Each t As TabPage In ApplicantTab.TabPages
            If Not hiddenPages.Contains(t) Then
                For Each de As DictionaryEntry In Responses(ResponseKey)

                    If Responses(ResponseKey).Count <> 0 Then
                        instAnswer.applicantID = appList(counter).applicantId
                        instAnswer.applicationID = instApplication.applicationId
                        For Each dict As DictionaryEntry In questionHash
                            If de.Key = dict.Value Then
                                instAnswer.questionID = dict.Key
                            End If
                        Next

                        If de.Value = "Yes" Then
                            instAnswer.answer = True
                        Else
                            instAnswer.answer = False
                        End If
                        instAnswer.Create()
                    End If

                Next
                counter += 1
            End If
        Next
    End If

End Sub

0 个答案:

没有答案