vb.net - Get combobox selected from another form dynamically -


i have combobox in form1 , datagridview in form2. want combobox selected value datagridview in second form use code below in form2 , works:

   private sub datagridview1_celldoubleclick(byval sender object, byval e system.windows.forms.datagridviewcelleventargs) handles datagridview1.celldoubleclick              form1.cbo_fournisseur.text = datagridview1.rows(e.rowindex).cells(0).value.tostring          me.close()      end sub 

but want name of form passed dynamically avoid using , ifelse clause enumerate forms have in project use form2

private sub datagridview1_celldoubleclick(byval sender object, byval e system.windows.forms.datagridviewcelleventargs) handles datagridview1.celldoubleclick          if formbon2.name = "frm_bn_reception_cuir"             frm_bn_reception_cuir.cbo_fournisseur.text = datagridview1.rows(e.rowindex).cells(0).value.tostring          elseif formbon2.name = "frm_reception_acc_provisoire"             frm_reception_acc_provisoire.cbo_1.text = datagridview1.rows(e.rowindex).cells(0).value.tostring          end if            me.close()      end sub 

screen shot of 2 forms

i think i've got want do. suggest stop using form shared resource.

use constructor in form2:

private parentformcombo combobox public sub new(byval pcmb combobox)   parentformcombo = pcmb end sub 

then in doubleclick change text of parentformcombo

parentformcombo.text = datagridview1.rows(e.rowindex).cells(0).value.tostring 

then have stop using:

frmlist_view.show() 

now should use constructor instead (new()). following instead:

dim f new frmlist_view(cbo_fournisseur) 'or dim f new frmlist_view(cbo_1) f.show() 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -