Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh data driven combo box on a winform

I have a winform with a combo box thats filled from a query in the database. If I add a field to the database, the new field won't show up in the form until I close it and reopen it.

I was able to put in a MessageBox.Show() and once that popped up, I closed it, and saw the new data in the combo box.

EDIT:

Let me clarify a bit. I have a dropdown combo box, and that is populated by a table adapter. I just did the databinding with the GUI so I'm not sure how it works.

What I want is, I want the new data that I enter to be refreshed when I come back to it. I have a seperate window to manage the data, and then I close it I want the combo box to be updated with what I just saved.

Is this possible? I tried to do it on form load but that doesn't work either, I think because the form is already loaded.

like image 442
Christof Avatar asked Dec 14 '22 01:12

Christof


1 Answers

The Refresh method is not for that. What you want to achieve is refreshing the data binding. This would be sth like this:

cb.DataBindings[0].ReadValue();

Another way is using a data source that supports change notification. Such a data source fires ListChanged event with appropriate parameters to trigger update of controls that are bound to it.

like image 67
kubal5003 Avatar answered Dec 15 '22 15:12

kubal5003