How to reload form in c# when button submit in another form is click? -


i have combo box in c# place in form named frmmain automatically fill when add (using button button1_click) product in settings form named frmsettings. when click button button1_click want reload frmmain new added product visible.

i tried using

frmmain main = new frmmain(); main.close(); main.show(); 

i know code funny didn't work. :d

this windows form!

edit

please see image of program better understanding. frmmain enter image description here

here settings frmsettings form like. so, can see when click submit button want make frmmain reload updated value added settings visible frmmain combobox.

enter image description here

update: since changed question here updated version update products

this products form:

private frmmain main;  public frmsettings(frmmain mainform) {   main = mainform;   initializecomponent(); }  private void button1_click(object sender, eventargs e) {   main.addproduct(textbox1.text); } 

it need mainform in constructor pass data it.

and main form:

private frmsettings settings; private list<string> products = new list<string>();  public frmmain() {   initializecomponent();   //load products somewhere }  private void button1_click(object sender, eventargs e) {   if (settings == null)   {     settings = new frmsettings(this);   }   settings.show(); }  private void updateform() {   comboboxproducts.items.clear();   comboboxproducts.items.addrange(products.toarray());    //other updates }  public void addproduct(string product) {   products.add(product);   updateform(); } 

you can call updateform() everywhere on form, button example. example uses local variable store products. there missing checks adding product, guess idea...


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -