c# - send information from one form to another WindowsForms -


i have problem: have forms. 1 form has datagridview , button. when click the button, creating form2, input information. , these information need add datagridview on first form. when click button "add" in form2, have error nullreferenceexception unhandled(object reference not set instance of object.). please me!

form1

private string client = null;     private string driver = null;     private string carmodel = null;     private string carkey=null;      public string goodsname2 = null;     public string goodsprice2 = null;     public string goodscount2 = null;     addwaybilgoods add_waibil_goods = null;      public waybil()     {         initializecomponent();         base base_ = new base(share.server_address, share.login, share.password, share.database);         base_.fill_combo(comboclients, "clients", "clientsname");         base_.fill_combo(combodrivers, "drivers", "driversname");         base_.fill_combo(combomodel, "cars", "carsmodel");     }      private void create_click(object sender, eventargs e)     {         client = comboclients.selecteditem.tostring();         driver = combodrivers.selecteditem.tostring();         carmodel = combomodel.selecteditem.tostring();         carkey =key.text.tostring();         word.application word = new word.application();         word.visible = true;         word.document doc = word.documents.add();         doc.select();         word.selection.typetext(client);         word.selection.typetext(driver);         word.selection.typetext(carmodel);         word.selection.typetext(carkey);     }      private void add_click(object sender, eventargs e)     {         add_waibil_goods = new addwaybilgoods();         add_waibil_goods.owner = this;         add_waibil_goods.show();         add_waibil_goods.focus();         datagridview1.rows.add(goodsname2,goodsprice2, goodscount2);         datagridview1.update();     }      private void combomodel_selectedindexchanged(object sender, eventargs e)     {         carmodel = combomodel.selecteditem.tostring();         base base_ = new base(share.server_address, share.login, share.password, share.database);         base_.find_item(key, "cars", "carskey", "carsmodel", carmodel);     } } 

form2

public partial class addwaybilgoods : form {     waybil w_b = null;     public string goodsname1 = null;     public string goodsprice1 = null;     public string goodscount1 = null;      public addwaybilgoods()     {         initializecomponent();         w_b= this.owner waybil;         base base_ = new base(share.server_address, share.login, share.password, share.database);         base_.fill_combo(addwaybilgoods1, "goods", "goodsname");     }      public void Добавить_click(object sender, eventargs e)     {         goodscount1 = count.text.tostring();         w_b.goodsname2 = this.goodsname1;         w_b.goodsprice2 = goodsprice1;         w_b.goodscount2 = goodscount1;         this.close();     }      private void addwaybilgoods1_selectedindexchanged(object sender, eventargs e)     {         goodsname1 = addwaybilgoods1.selecteditem.tostring();         base base_ = new base(share.server_address, share.login, share.password, share.database);         base_.find_item(price, "goods","goodsprice", "goodsname", goodsname1);         goodsprice1 = price.text.tostring();     } } 

updating following statements should fix issue

private void add_click(object sender, eventargs e) {     add_waibil_goods = new addwaybilgoods();     if (add_waibil_goods.showdialog(this) == dialogresult.ok)     {         datagridview1.rows.add(add_waibil_goods.goodsname2, add_waibil_goods.goodsprice2, add_waibil_goods.goodscount2);         datagridview1.update();     } } 

it appears referencing properties in form1 when adding datagridview1. need start form2 modal window. modal window ensure user fills in correct data before application continues.

http://msdn.microsoft.com/en-us/library/c7ykbedk(v=vs.110).aspx


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -