I'm trying to set the selected value from a combo box that is populated from my database,
i cant seem to find a way to do that.

I'm using this to populate my combo box:
Private Sub PopulateCountry()
Dim country As New Client
Dim contryList As OdbcDataReader = country.mpopulateCountry()
Dim objCountry As String
If contryList.HasRows Then
Do While contryList.Read
objCountry = contryList(0)
End If
End Sub

And calling this method(PopulateCountry()) in the form load and then using this to set the value upon my button btnAddToDB:
Dim country As String
country = cbxCCountry.SelectedValue

Any suggestion guys?

Recommended Answers

All 3 Replies

This is how I did it-

Public Class Form4

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cn As New Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=mydb; User=root;Password=xxxxx;")
        Dim cmd As New Odbc.OdbcCommand("Select * from mytable", cn)
        Dim dr As Odbc.OdbcDataReader
        dr = cmd.ExecuteReader
        While dr.Read
            ' dr(i) where i is the column cardinal
            ' if the 2nd field is needed it should be dr(1)

        End While
    End Sub
End Class

just solved it. my code works i just got mixed up with the ".SelectedItem" and ".SelectedValue". :D

hi jalandoonk,

can u give me the code for
"-- how to set the selected value of Combobox..--"

I hav been struggling with it since past 4days..

venu... venu_hm@hotmail.com

Be a part of the DaniWeb community

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