Results 1 to 6 of 6

Thread: [RESOLVED] [2008] Combo Update

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2009
    Posts
    39

    Resolved [RESOLVED] [2008] Combo Update

    I have a form wich contains a combobox that is filled from a sql databse table,
    this combo is named ManufacturerComboBox.
    If a manufacturer is not already entered into the database you can click a label and it invokes another form called Add Manufacturer.
    everything works ok except after i enter a new manufacturer into the Add Manufacturer datagrid it doesnt refresh into the ManufacturerComboBox unless i exit the Form and re-enter.
    What is a good way to repopulate this combo box?

    The combo box is in unbound mode and is populated by code:

    With ManufacturerComboBox
    .DisplayMember = "Manufacturer"
    .ValueMember = "ManufacturerID"
    .DataSource = GetManufacturers() 'public sub
    End With

    In the Add Manufacturer form in the closing event:

    Me.AddManDataGridView.Update()
    Me.AddManManufacturersTableAdapter.Update(Me.MemKingDataSet.AddManManufacturers)
    AuditItem.Refresh() ' audit item is the name of the form that the combo box resides.

    I tried to use AuditItem.ManufacturerComboBox.update() in the form closing event but it didnt work, what is the best wat to handle this?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Combo Update

    First up, your ComboBox is NOT unbound. Data-binding isn't done just in the designer. All the designer does is generate code for you, so you can write the same code and bind yourself. If you set the DataSource property then you're binding, plain and simple.

    As for the question, the problem is that you're getting the data and binding it to the ComboBox but then you make changes to some other data. You should be binding the ComboBox to the same data that you make changes to and then save. Alternatively, you can simply re-get the data to bind to the ComboBox. You called GetManufacturers to populate it in the first place. Just call GetManufacturers again.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2009
    Posts
    39

    Re: [2008] Combo Update

    Ive been trying to do that, the problem is, i am not 100% sure what event to place the code into.
    A separate window opens, i enter the new manufacturer, then i close the window. I called getmanufacturers() on the closing event in the new manufacturer window, is this the right place to put it?
    is there a way to tell the parent window that the add manufacturer window is open and when it closes to the call getmanufacturers()?

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2009
    Posts
    39

    Re: [2008] Combo Update

    Also i cant really bind the combo box to that data-source because it is dynamically populated according to an ID column in the database.

    Each item contains computer specs, so if i need to pull that specific item up it fills the combo boxes and text fields according to what is contained in the database for that ID Row. I hope that makes sense.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Combo Update

    I assume that you're displaying this other window by calling ShowDialog. I would simply test the result of ShowDialog and, if it's OK, repopulate the ComboBox.

    I'm not sure what you mean by post #4. If you mean that the item selected in the ComboBox is determined by a different binding then that should be no problem. The selected item is still going to exist after to rebind so it should be reselected automatically.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2009
    Posts
    39

    Re: [2008] Combo Update

    Actually i was foolishly using .show() and not showdialog().
    Anyway i added the OK button and the Cancel button to the AddManufacturer form and added the appropriate code the the OK and it works like a champ.
    Thank You very much!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width