none
Bound Combo box not updating after row add RRS feed

  • Question

  • I have  a combo box that is bound to a dataset using the IDE. When I add a row to the table it does not reflect the change in the combo box until after I close the program down and restart it back up.
    To update the underlying table I open a form from the main form and ask the user for information to add.
    Then I call the following function to add the info.

    Public Sub AddRowToTable()
            Dim daAddItem As New OleDb.OleDbDataAdapter
            Dim MySQL As String = ""
            Dim rowNewRace As DataRow
            Dim dsAddItem As New DataSet

             MySQL = "SELECT * FROM tblDrivers;"
     
            daAddItem = New OleDb.OleDbDataAdapter(MySQL, oleConn)
            daAddItem.Fill(dsAddItem, "AddItem")
            '!!!! The following line needs to be here to create the update commands properly
            Dim cbAddItem As New OleDb.OleDbCommandBuilder(daAddItem)
            '/ make an empty row
            rowNewRace = dsAddItem.Tables("AddItem").NewRow()
            '/ Add values to row
            rowNewRace.Item(1) = sItem
            '/ attach new row to table
            dsAddItem.Tables("AddItem").Rows.Add(rowNewRace)
            '/ update database table with new row
            daAddItem.Update(dsAddItem, "AddItem")

            frmMain.cboDriver.Refresh()
     
    End Sub


    My binding source for the combo box in the IDE is set to TblDriversBindingSource
    which gets its info from the above tblDrivers table

    Here is what I did try:
        refreshing the combo box
        resetting the binding source at the end of the procedure
        called EndEdit on binding source    TblDriversBindingSource.EndEdit()
        refresh the main form

    Thank you for your time and patience. If you need more info let me know.
    Wednesday, December 2, 2009 1:10 PM

Answers


  • Yes, it would force combobox to refresh, and show the data but if it has data ..

    Maybe you have to break point in loading data to combobox, maybe there aren't any data to load to combobox, so you can't see anything there..

    Try to trace every line in code especially loading data to combobox and add variable to watch so you can see changing in every variable..

    I m sure you can do that.. evaluate every result in line, and you will see what's going on with your combobox  ;)
    Friday, December 4, 2009 2:20 AM

All replies

  • Did you set the datasource like I showed in that previous message, I gues not, otherwise after this code it should be in your combobox.


    Success
    Cor
    Wednesday, December 2, 2009 5:59 PM
  • Did you set the datasource like I showed in that previous message, I gues not, otherwise after this code it should be in your combobox.


    Success
    Cor

    I looked at the previous message and do not see how you showed me to set the datasource.
    Like I said above I bound the combobox in the IDE. trying to get the combobox to see the new row that was added I tried to set the binding again in code. I read on another site that sometimes that needs to be done to refresh. I realize it should be in my combobox after the code, that is what I am struggling with to understand. If you need some more info to go on please let me know.
    I truly appreciate your time. I have Googled this and tried some things that I have found but I'm again hitting a wall. I just need a push in the right direction. Seems like since the row is added to the table as evident when I restart the program it has the new data. I just am missing some step somewhere.

    Thank you again for your time and understanding.
    Wednesday, December 2, 2009 6:20 PM
  • Have you tried to re-run the "fill" on the table adapter? In fact you'll most likely find that in your form's load event so just copy that and at the end of your process of adding records, paste it.

    For example, one from one I recently worked on:

    Me.FHGTableAdapter.Fill(Me.FHGDataSet.FHG)

    Good luck! :)
    Wednesday, December 2, 2009 10:30 PM
  • Yes, I did do that. But still no joy. :(
    Thank you for the suggestion.
    Wednesday, December 2, 2009 10:32 PM
  • Yes, I did do that. But still no joy. :(
    Thank you for the suggestion.


    That is a conundrum then. Hmm ... I'm drawing a blank.

    I hope you get it figured out; sorry I couldn't be of more assistance.

    Thursday, December 3, 2009 12:35 AM
  • Okay, I'm even more confused. I have ran the program and have added data for a new row, as before it does not show in the combo box. If I keep the program running and add another row, the first row now appears in the combo box along with the original data.
    I have done a refresh() on the main form and the combo box thinking that was the issue. And have tried DoEvents().
    Do I need to tell the bindingsource that a change has been made to the underlining table?


    Thursday, December 3, 2009 1:38 AM

  • Try to auto refresh it in 'n' seconds.. Use timer to make auto refresh

    If this can help you, maybe it's just because the combobox need time to refresh new data
    Thursday, December 3, 2009 4:53 AM
  • Yea,

    I see now there is somebody else with yesterday almost the same problem like you.

    He did not set it datasource to the combobox right, in what way did you do that?
    Success
    Cor
    Thursday, December 3, 2009 6:08 AM
  • Harrie KalaChakra:
    I tried to use the timer and left it at the default setting. In the event of the timer I have the form refreshing and also the combo box. When the program is running I can see the form refreshing but the combo box still does not update. I do have a question After I update the table I have the form and combo box refreshing then I have Application.DoEvents(). Wouldn't this force the combo box to update its data?

    Cor Ligthert:
    I set my bindings up through the IDE
    I have a table tblDrivers
    with two columns: tblDriver_Name and tblsDriver_ID
    The ID column is set as autonumber and this is the key
    In the IDE for the combo box these are the settings
    DataSource = tlbDriversBindingSource
    DisplayMember = tblDriver_Name
    ValueMember = tblDriver_ID

    What has me stumped is if my bindings were not right, why does the combo box update after the second run

    Thank you guys for all your help with this it is very much appreciated.
    Thursday, December 3, 2009 11:56 PM
  • I'm not sure that you're up for re-working it, but have a look at this thread:

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/4d743669-c7cd-4ade-a3e1-8c20f8f67361

    The topic is actually about the AutoComplete, but in it, I set up a combobox bound to a database table and field. It may (or may not) give you some insight.

    Good luck! :)
    Friday, December 4, 2009 1:16 AM

  • Yes, it would force combobox to refresh, and show the data but if it has data ..

    Maybe you have to break point in loading data to combobox, maybe there aren't any data to load to combobox, so you can't see anything there..

    Try to trace every line in code especially loading data to combobox and add variable to watch so you can see changing in every variable..

    I m sure you can do that.. evaluate every result in line, and you will see what's going on with your combobox  ;)
    Friday, December 4, 2009 2:20 AM
  • What is the datasource of  tlbDriversBindingSource

    What you do comes often because people make code like this.

    BindingSource = myDataTable

    And then somewhere
    myDataTable = new DataTable

    The reference stays at the old myDataTable as long as you don't refresh that datasource as well (not the combobox itself)
    Success
    Cor
    Friday, December 4, 2009 7:27 AM