Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

Learning VB.Net on my own. I'm connected to a database using ODBC and I'm able to retrieve data to fill in a combo box. When I click on an item in the combo box, I want to retrieve the corresponding data for the record I selected and fill in the required data fields on the form. I know how to fill in the remaining fields. I don't know how to get from clicking the combo box to retrieving the remaining data.

Can any one explain to me or provide me with the code to achieve this result?

Thanks.
Posted

1 solution

Handle the SelectedIndexChanged event, and use the SelectedItem property:
VB
Private Sub myComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles myComboBox.SelectedIndexChanged
    Dim cb As ComboBox = TryCast(sender, ComboBox)
    If cb IsNot Nothing Then
        Dim item As String = DirectCast(cb.SelectedItem, String)
        ...
    End If
End Sub

I would strongly suggest you find a course, or a book - they present the material in a structured way, which should ensure that you do not miss important details as you go along. If you try to learn by "just doing it" I guarantee you will be missing lots as you go, and making things a lot harder for yourself than you need to!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900