Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Dynamic Combobox - refresh list items on the fly

Dynamic Combobox - refresh list items on the fly

Scheduled Pinned Locked Moved Windows Forms
databasesalestutorialannouncement
4 Posts 2 Posters 13 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CaptainSpecial
    wrote on last edited by
    #1

    I have a main form where the user selects a customer from a drop down box. On this form is also a button that opens another form as a dialog that allows the user to enter a new customer. The user clicks "Save" on the new customer dialog and the customer is saved to the database and the main form becomes active again. I can't figure out how to update the combobox so that it displays this new customer in the list. The combobox is bound to a datasource. I know the code to create and save a new customer is working since the change is reflected in the database. The new customer also appears in the combobox BUT only after I close and run the application again. // if a new customer was added to the database/dataset refresh combobox since there should be a new item if (result == DialogResult.OK) { // code to refresh combobox should go here }

    C 1 Reply Last reply
    0
    • C CaptainSpecial

      I have a main form where the user selects a customer from a drop down box. On this form is also a button that opens another form as a dialog that allows the user to enter a new customer. The user clicks "Save" on the new customer dialog and the customer is saved to the database and the main form becomes active again. I can't figure out how to update the combobox so that it displays this new customer in the list. The combobox is bound to a datasource. I know the code to create and save a new customer is working since the change is reflected in the database. The new customer also appears in the combobox BUT only after I close and run the application again. // if a new customer was added to the database/dataset refresh combobox since there should be a new item if (result == DialogResult.OK) { // code to refresh combobox should go here }

      C Offline
      C Offline
      CaptainSpecial
      wrote on last edited by
      #2

      Figured it out. The quick answer is to simply fill the dataset again. However, if you have any filters elsewhere on the form that use the same dataset, be prepared to deal with exceptions. You must put some data back into the dataset before any calls to the filter are made. This was a big issue for me and took me about 8-10 total hours of debugging to figure out. Then again, I am a complete noobie.:laugh:

      R 1 Reply Last reply
      0
      • C CaptainSpecial

        Figured it out. The quick answer is to simply fill the dataset again. However, if you have any filters elsewhere on the form that use the same dataset, be prepared to deal with exceptions. You must put some data back into the dataset before any calls to the filter are made. This was a big issue for me and took me about 8-10 total hours of debugging to figure out. Then again, I am a complete noobie.:laugh:

        R Offline
        R Offline
        RabidHamster
        wrote on last edited by
        #3

        Glad you figured it out. But you may want to take a look at Update Controls .NET. These controls update themselves from your own data objects, not from datasets. So when you add your customer object to your list, it would automatically refresh the drop down.

        C 1 Reply Last reply
        0
        • R RabidHamster

          Glad you figured it out. But you may want to take a look at Update Controls .NET. These controls update themselves from your own data objects, not from datasets. So when you add your customer object to your list, it would automatically refresh the drop down.

          C Offline
          C Offline
          CaptainSpecial
          wrote on last edited by
          #4

          Thanks for the link. I have checked it out and I will at least experiment with some of those controls.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups