Hello,
could anyone please help me with this? I have a form with 4 comboboxes. The comboboxes are SBUName, Maindepartment, Team and Staff. When the High level combobox which in this case is the SBUName is selected then the preceding lower level comboboxes will all be populated with data (by SelectedIndexChange). When the form loads the SBUName is prepopulated with the SBU Names, and since SBUName_SelectedIndexChange is set to prepopulate the MainDepartment with related data, the Maindepartment should have the related data prepopulated as well; this then continues the chain to prepopulate the Team combobox via MainDepartment_SelectedIndexChanges. However, for the first two comboboxes (SBUName adn Maindepartment) its working as cmbSBUName.SelectedIndex = 0, but for the MainDepartment when I set SelectedIndex = 0 to prepopulate Team combobox it gives me an error, and this continue in that fashion with the other preceeding comboboxes. Please help me. Part of my code is as shown below.

Private Sub frmAbsentReport_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            'Load Department Names.
            objAbsent.LoadSBU()
            If strAdminAccess = True And strSystemAdminAccess = True Then
                'Screen Access by System Admin.
                With Me.cmbSBUName
                    .DataSource = objAbsent.dss.Tables("SBUName")
                    .DisplayMember = "SBUName"
                    .Enabled = True
                    .SelectedIndex = 0
                End With
                cmbSBUName.Enabled = True

            ElseIf strAdminAccess = True And strSystemAdminAccess = False Then
                'Screen Access by Manager and Team Leader
                With Me.cmbSBUName
                    .DataSource = objAbsent.dss.Tables("SBUName")
                    .DisplayMember = "SBUName"
                    .Enabled = False
                    .SelectedIndex = cmbSBUName.FindStringExact(strSBU)
                End With
                cmbSBUName.Enabled = False

            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        'Try

        '    'Load Department Names.
        '    objAbsent.LoadSBU()

        '    With Me.cmbSBUName
        '        .DataSource = objAbsent.dss.Tables("SBUName")
        '        .DisplayMember = "SBUName"
        '        .SelectedIndex = cmbSBUName.FindStringExact(strSBU)
        '    End With
        '    Me.WindowState = FormWindowState.Normal
        'Catch ex As Exception
        '    MessageBox.Show(ex.Message)
        'End Try
    End Sub

    Private Sub cmbSBUName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbSBUName.SelectedIndexChanged
        Try
            'Loads the main department names..
            objAbsent.LoadMainDept(cmbSBUName.Text)

            If strAdminAccess = True And strSystemAdminAccess = True Then
                'Screen Access by System Admin.
                With Me.cmbMainDepartment
                    .DataSource = objAbsent.dss.Tables("MainDepart")
                    .DisplayMember = "MainDepartment"
                End With
               
            ElseIf strAdminAccess = True And strSystemAdminAccess = False Then
                With Me.cmbMainDepartment
                    .DataSource = objAbsent.dss.Tables("MainDepart")
                    .DisplayMember = "MainDepartment"
                    .SelectedIndex = cmbMainDepartment.FindStringExact(strMainDep)
                End With
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        'Try
        '    'Loads the main department names..
        '    objAbsent.LoadMainDept(cmbSBUName.Text)

        '    With Me.cmbMainDepartment
        '        .DataSource = objAbsent.dss.Tables("MainDepart")
        '        .DisplayMember = "MainDepartment"
        '        .SelectedIndex = cmbMainDepartment.FindStringExact(strMainDep)
        '    End With
        'Catch ex As Exception
        '    MessageBox.Show(ex.Message)
        'End Try
    End Sub

    Private Sub cmbMainDepartment_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbMainDepartment.SelectedIndexChanged
        Try
            'Loads the main department names..
            objAbsent.LoadTeam(cmbMainDepartment.Text)

            If strAdminAccess = True And strSystemAdminAccess = True Then
                'Screen Access by System Admin.
                With Me.cmbTeam
                    .DataSource = objAbsent.dss.Tables("TeamName")
                    .DisplayMember = "Team"
                    .SelectedIndex = 0
                End With

            ElseIf strAdminAccess = True And strSystemAdminAccess = False Then
			'Screen Access by Manager and Team Leader
                With Me.cmbTeam
                    .DataSource = objAbsent.dss.Tables("TeamName")
                    .DisplayMember = "Team"
                    .SelectedIndex = cmbTeam.FindStringExact(strTeam)
                End With
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try



        'Try

        '    objAbsent.LoadTeam(cmbMainDepartment.Text)

        'With Me.cmbTeam
        '    .DataSource = objAbsent.dss.Tables("TeamName")
        '    .DisplayMember = "Team"
        '    .SelectedIndex = cmbTeam.FindStringExact(strTeam)
        'End With
        'Catch ex As Exception
        '    MessageBox.Show(ex.Message)
        'End Try
    End Sub

I think tou missed to set the selected index to 0 for the cmbMainDepartment when the if strAdminAccess and strSystemAdminAccess are both true.

Hope this helps

I think tou missed to set the selected index to 0 for the cmbMainDepartment when the if strAdminAccess and strSystemAdminAccess are both true.

Hope this helps

Thanks lolafuertes for the reply.

Yes I did that but then it gave me an erro. So when I remove the SelectedIndex = 0 then the error is not there.

That maybe because the MainDepart table of the objAbsent.dss is empty. Can you check it?

How and when do you fill the tables?

That maybe because the MainDepart table of the objAbsent.dss is empty. Can you check it?

How and when do you fill the tables?

No, its not empty. I just can't figure out how to make this work. Anyway thanks again for your replies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.