views:

43

answers:

1

I am populating combo box from database. In debug i can see that the combo box has been populated .

here is the code

Private Sub ComboID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboID.SelectedIndexChanged

        Dim data(21) As String
        Try
            t_code.Text = ComboID.SelectedItem(0)
            ComboID.Visible = False
            data = getData(t_code.Text)

            populateFields(data)


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

but when i run this program i get error:Object variable or with block variable not set error

i would really appreciate your help. Thanks

A: 

Just knowing that the combobox is populated is not enough. You should still be testing for

SelectedIndex >= 0

It is possible that SelectedIndex is changing to -1 if the user clears the selection.

Of course, it is also quite likely that getData is returning Nothing and populateFields can't handle that. It would probably throw a

If data isNot Nothing
end if

test around the populateFields call, too. It never hurts to test for edge cases.

Bill