mardi 25 août 2015

If statement to disable ComboBoxes based on data being present

I have 6 combo boxes and one button. The first combo box is enabled and the rest are disabled on form load. I have them set to drop down list's and attached to a data source from a SQL table. I want the data in the first box to make the second box query its table and only display values from matching data, so I need them to enable in order and disable if someone tries to set an early box back to no value. I have a chained if statement currently, and I just have a gut feeling that it's bad programming, and was wondering what I could do better.

    Private Sub CheckNotEmpty(ByVal Sender As Object, ByVal e As EventArgs)
    If YearDDB.SelectedText Is Nothing Then
        MakeDDB.Enabled = False
        ModelDDB.Enabled = False
        ModifierDDB.Enabled = False
        StyleDDB.Enabled = False
        LocationDDB.Enabled = False
        SearchButton.Enabled = False
    Else
        MakeDDB.Enabled = True
        If MakeDDB.SelectedText Is Nothing Then
            ModelDDB.Enabled = False
            ModifierDDB.Enabled = False
            StyleDDB.Enabled = False
            LocationDDB.Enabled = False
            SearchButton.Enabled = False
        Else
            ModelDDB.Enabled = True
            If ModelDDB.SelectedText Is Nothing Then
                ModifierDDB.Enabled = False
                StyleDDB.Enabled = False
                LocationDDB.Enabled = False
                SearchButton.Enabled = False
            Else
                ModifierDDB.Enabled = True
                If ModifierDDB.SelectedText Is Nothing Then
                    StyleDDB.Enabled = False
                    LocationDDB.Enabled = False
                    SearchButton.Enabled = False
                Else
                    StyleDDB.Enabled = True
                    If StyleDDB.SelectedText Is Nothing Then
                        LocationDDB.Enabled = False
                        SearchButton.Enabled = False
                    Else
                        LocationDDB.Enabled = True
                        If LocationDDB.SelectedText Is Nothing Then
                            SearchButton.Enabled = False
                        Else
                            SearchButton.Enabled = True
                        End If
                    End If
                End If
            End If
        End If
    End If
End Sub

Aucun commentaire:

Enregistrer un commentaire