I have a combobox that is bound to a DB and works great. However, when the user adds a value to the table to which the combobox is bound, the combobox keeps the old value and adds the current items in the table. In this case the table originally held just one record ("2012"). The user added 2013 so the table now shows two records ("2012" and "2013"), but the combobox shows three records ("2012", "2012", and "2013"). UNTIL I exit the app and restart, in which case it correctly reflects the only two records in the table ("2012" and "2013"). I have tried cboYear.Datasource = Nothing, cboYear.items.clear, cboYear.DataBindings.clear and nothing works. Here is the code.

            Dim asql As String = ("SELECT * FROM YearsAvailable ORDER BY CurrentYear")
            Dim da As New OleDbDataAdapter(asql, con)

            cboYear.ValueMember = "CurrentYear"
            cboYear.DataSource = ds.Tables(0)
            cboYear.SelectedIndex = 0
            CurrentYear = cboYear.Text
            Me.Text = "MSD of Perry Township Compensation Model: " & CurrentYear


        Catch ex As Exception
            MsgBox("ERROR filling the YEAR control: " & ex.Message.ToString)
        End Try
3 Years
Discussion Span
Last Post by kindofsudden

I tested your code and it was right. But, somehow, your ds did not change during run time and it makes your combobox couldn't change, too.
My recommendation: Place your combobox loading sub on some where it continually checking SQL and update a new dataset when your SQL table change.
Hope this help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.