Get comboBox value from another form in C# -
i have 2 forms, in form1 there button show form2. in form2 have combobox. after selecting item combobox, user can click button send combobox value form1 , form2 close.
here code:
form1:
private void button1_click(object sender, eventargs e) { form2 frm2 = new form2(); frm2.showdialog(); }
form2:
private void button1_click(object sender, eventargs e) { form1 frm1 = new form1(); frm1.textbox1.text = convert.tostring(combobox1.selectedvalue); this.dialogresult = dialogresult.ok; }
but combobox value doesn't appear @ textbox on form1saas
you trying set value in combobox of new form, because create here:
form1 frm1 = new form1();
you should pass reference form1 instance form2 (via constructor or member field).
the correct way add private member field of type form1 form2 class, add parameter form2 constructor, , initialize on constructor call:
var form2 = new form2(this);
then reference member field.
Comments
Post a Comment