c# - How to pass the value from child form to parent form? -
i have 2 forms called billingform(parent form) , searchproduct(child form).
billingform code
private void textboxproductno_keydown(object sender, keyeventargs e) { if(e.keycode==keys.f9) { using(searchproduct sp=new searchproduct) { sp.showdialog(this); } } } public void updatedtext(string fromchildform) { textboxproduct.text=fromchildform; }
searchproduct form code (child form)
private void datagridview1_keydown(object sender,keyeventargs e) { if(e.keycode==keys.enter) { billingform bf=(billingform)this.owner; //error appear here bf.updatedtext("hello world"); this.close(); } }
i getting error message.
an unhandled exception of type 'system.invalidcastexception' occurred in billingsoftware.exe
additional information: unable cast object of type 'billingform.mdiparent' type 'billingform.billingform
try pass parent constructor , use in variable
using(searchproduct sp = new searchproduct(this)) { sp.showdialog(this); } //in searchproduct class public billingform myparent {get; private set;} public searchproduct(billingform parent) { this.myparent = parent; } private void datagridview1_keydown(object sender,keyeventargs e) { if (e.keycode == keys.enter) { billingform bf = this.myparent; bf.updatedtext("hello world"); this.close(); } }
Comments
Post a Comment