winforms - Passing Value from One Form to Another (C#) -


i have search form in program. when user double-clicks cell (of dgv) on search form, want program close form , jump item on main form.

i'm doing identifying each item unique id.

i'm trying pass value of rows id other form. problem that, says i'm passing value 0 each time. when insert message boxes on search form, says integer 'id' has been assigned variable on main form: public int celldoubleclickvalue { get; set; }

here code:

search form:

    private int id;      private void searchdgv_celldoubleclick(object sender, datagridviewcelleventargs e)     {         this.rowindex1 = e.rowindex;         this.id = convert.toint32(this.searchdgv.rows[this.rowindex1].cells["id"].value);         invmain inv = new invmain();         inv.celldoubleclickvalue = this.id;         this.dialogresult = dialogresult.ok;         this.close();         //messagebox.show(inv.celldoubleclickvalue.tostring());          //above, shows got assigned successfully.     } 

main form:

    public int celldoubleclickvalue { get; set; }      private void searchtoolstripmenuitem_click(object sender, eventargs e)         {         search form1 = new search();         form1.showdialog();          if (form1.dialogresult == dialogresult.ok)         {             messagebox.show(celldoubleclickvalue.tostring());         }//here shows value is: 0 

i suggest follows:

search form:

public int selectedid { get; set; }  private void searchdgv_celldoubleclick(object sender, datagridviewcelleventargs e) {     this.rowindex1 = e.rowindex;     this.selectedid = convert.toint32(this.searchdgv.rows[this.rowindex1].cells["id"].value);     this.dialogresult = dialogresult.ok;     this.close(); } 

main form:

private void searchtoolstripmenuitem_click(object sender, eventargs e) {     search form1 = new search();     form1.showdialog();      if (form1.dialogresult == dialogresult.ok)     {         int selectedid = form1.selectedid;         // whatever selectedid...     } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -