This one has me stumped. I feel like it is something really simple, but I can't figure it out.

I have a combobox that is triggering the population of some checkboxes depending on the user mode. For some reason, when I put a MsgBox() at the beginning of the function, it works fine. But without that MsgBox(), I get the error that there is no row at position 0.

Anyone have any ideas?

MsgBox("value changed") '<---- this is the box that clears the error

        'display the name once the number has been selected
        Me.lblAssocName.Text = Me.cmbAssocID.SelectedValue.ToString

        Try
            'populate a table with that associate's information
            Dim tblassoc As New DataSet1.assocStatusDataTable
            Me.AssocStatusTableAdapter.FillByAssocID(tblassoc, Convert.ToString(Me.cmbAssocID.SelectedText))

            'set the information of the associate dependent on the mode

            'setting the associate's status...
            If Me.btnAssocStatus.BackColor = Color.Green Then
                
                If tblassoc.Rows(0).Item("groupleader") = True Then '<-- this is where 
                                                                    '    error occurs.
                    Me.chkTeamLead.Checked = True
                Else
                    Me.chkTeamLead.Checked = False
                End If
                If tblassoc.Rows(0).Item("status") = True Then
                    Me.chkActive.Checked = True
                Else
                    Me.chkActive.Checked = False
                End If

            End If
End Sub

This might be silly, but:
How is your combobox getting it's values? Could it be that you've got a background worker or something running when you are checking for row(0) and the msgbox is just giving the necessary time for the operation to complete?

The message box line is above the line where the table gets populated. Line 1 in the code is where the MsgBox pops up, but Line 8 is where the table is being populated.

Thanks for the thought!

Showing a MessageBox normally force the form to update its layout. So whats happen if you do Me.Refresh instead of showing the MessageBox?

I put a Me.Refresh in place of the message box, but the error still comes up. To confirm, I put the MessageBox back in, and it worked again. :(

I placed a DataGridView in the window so that I can see if the table is actually being populated, and with what data.

When the MsgBox() is in the code, the table updates with the information required, but without the MsgBox, the table stays empty.

I'm not sure if this information helps anything. I'm just trying anything...

Try this
Remove the msgbox()
put this line instead

if cmbAssocID.SelectedValue Is Nothing then Exit Sub

I fixed it. I'm not sure why, but .SelectedText was not updating without that MsgBox().

Here is the working code:

Try
            'populate a table with that associate's information

            Dim tblassoc As New DataSet1.assocStatusDataTable
            tblassoc = Me.AssocStatusTableAdapter.GetByAssocID(Convert.ToString(Me.cmbAssocID.SelectedItem(0)))

            'set the information of the associate dependent on the mode

            'setting the associate's status...
            If Me.btnAssocStatus.BackColor = Color.Green Then

                If tblassoc.Rows(0).Item("groupleader") = True Then
                    Me.chkTeamLead.Checked = True
                Else
                    Me.chkTeamLead.Checked = False
                End If
                If tblassoc.Rows(0).Item("status") = True Then
                    Me.chkActive.Checked = True
                Else
                    Me.chkActive.Checked = False
                End If

            End If
Catch ex As Exception
            MsgBox(ex.ToString)
        End Try


    End Sub
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.