Reputation:
I have a c# application with multiple "worker" forms. These forms have numerous comboboxes that are populated from the database on form load, with 'add' buttons beside them. When a user clicks the add button the administrative form is opened allowing the user to add a corresponding value to the database.
For instance, the combobox may be a list of street types. "Drive" is not in the street types table in the database, so the user wants to add it. They click the add button and the admin form is loaded so they can add the "Drive" value to the street types. When the admin form closes, I want to repopulate the combobox upon return to the worker form.
Any insight as to the best way to accomplish this?
Upvotes: 0
Views: 1814
You can also do: Form1 frm = (Form1)Application.OpenForms["Form1"]; This will allow you to update the form from another one.
Upvotes: 0
Reputation: 7377
It takes more work to set it up if you haven't from the start, but if you're doing the proper MVP[~] thing, that child "Add" form should trigger an update in your model, which your controller observes, which reacts by updating that portion of the view.
[~] Martin Fowler has retired his use of the term Model-View-Presenter, but he's still waffling between Supervising Controller and Supervising Presenter as its replacement.
A couple references:
Upvotes: 0
Reputation:
Thanks guys. I used ShowDialog and it worked great.
Administration adminForm = new Administration(); adminForm.tcAdministration.SelectedIndex = 1; adminForm.ExistingCaseNumber = this.ExistingCaseNumber; adminForm.ShowDialog();
this.PopulateComboBoxes();
Upvotes: 1
Reputation: 5405
One way is to create the form as a modal form, and you can use the this.Parent, and access a public method from there that updates the combo box.
Upvotes: 0
Reputation: 74530
When the forms that can administer the lists is created, I'd add an event handler for the Closed event of the form. In that event handler is where I would reload the data source for the list, and then rebind it to the combobox.
Upvotes: 0