Dynamic Combobox - refresh list items on the fly
-
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 }
-
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 }
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:
-
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:
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.
-
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.
Thanks for the link. I have checked it out and I will at least experiment with some of those controls.