Combobox datasource issue

smpolk

Member
Joined
Nov 22, 2006
Messages
10
Programming Experience
1-3
Hi all -

I am having trouble getting my combobox to populate when i set the datasource to a datatable. I have checked to make sure the datatable has the correct data. I have checked to see if the combobox has any items in it, and it does. When i do ?me.cboMonth.Items.Count in the immediate window, it returns the correct number of items, but i still do not see anything in my dropdown list. :mad:

Help, please...anyone. My code is below:

Dim sqliteConStr As String = "DRIVER=SQLite3 ODBC Driver;Database=" & My.Settings.Repository_Path & ";Version=3;NoCreat=True;"
Dim sqliteConn As New Odbc.OdbcConnection(sqliteConStr)
Dim sql As String = "SELECT ID, Month FROM MonthList"
Dim sqliteDA As New Odbc.OdbcDataAdapter(sql, sqliteConn)
dtMonthList =
New DataTable("MonthList")
Try
sqliteDA.Fill(dtMonthList)
dtMonthList.CaseSensitive =
False
Me.cboMonth.DataSource = dtMonthList
Me.cboMonth.DisplayMember = "Month"
Me.cboMonth.ValueMember = "ID"
Me.cboMonth.SelectedIndex = CInt(Format(Today, "MM")) - 1
Me.txtYear.Text = Format(Today, "yyyy")
Catch ex As Exception
MsgBox(ex.Message)
Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Try
If Not sqliteConn Is Nothing Then sqliteConn.Dispose()
If Not sqliteDA Is Nothing Then sqliteDA.Dispose()
If Not dtMonthList Is Nothing Then dtMonthList.Dispose()
 
Hrmm... let me guess this right.... You bind your combo to a datatable.... then destroy the datatable, and then wonder why there's nothing in the combo box?

-tg
 
heh...oops...ok, i took that last line out, but there is still no data. The dropdown list is expanded to how long it needs to be now, but nothing is listed.

Updated code:
Dim sqliteConStr As String = "DRIVER=SQLite3 ODBC Driver;Database=" & My.Settings.Repository_Path & ";Version=3;NoCreat=True;"
Dim sqliteConn As New Odbc.OdbcConnection(sqliteConStr)
Dim sql As String = "SELECT ID, Month FROM MonthList"
Dim sqliteDA As New Odbc.OdbcDataAdapter(sql, sqliteConn)
dtMonthList =
New DataTable("MonthList")
Try
sqliteDA.Fill(dtMonthList)
dtMonthList.CaseSensitive =
False
Me.cboMonth.DataSource = dtMonthList
Me.cboMonth.DisplayMember = "Month"
Me.cboMonth.ValueMember = "ID"
'Me.cboMonth.SelectedIndex = CInt(Format(Today, "MM")) - 1
'Me.txtYear.Text = Format(Today, "yyyy")
Catch ex As Exception
MsgBox(ex.Message)
Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Try
If Not sqliteConn Is Nothing Then sqliteConn.Dispose()
If Not sqliteDA Is Nothing Then sqliteDA.Dispose()
'If Not dtMonthList Is Nothing Then dtMonthList.Dispose()
 
where/how is dtMonthList declared? I don't see it in the sample.

-tg
 
Did you set the display member on the combo? How will it know, otherwise, which column of the datatable to render into the list?
 
Well...thanks for all the replies. Im not sure exactly what happened, but i transferred the project to a different computer and it is working now. I only made one change to the code. I changed:

Dim dtMonthList as DataTable

to:

Private dtMonthList as DataTable

That shouldnt have made a difference, i dont think. Anyways, it is working now. Thanks again.
 
Back
Top