vb.net - pass datarow from a different form using multiple RaiseEvents -
i've got 2 forms. frmproject has ultragrid of system rows. when double-click on row, opens frmsystem, displaying textboxes populated details active row on frmproject.
i want frmsystem load same values specified in ultragridrow on frmproject. don't want frmsystem load values database table tbl_system. because if user makes changes in frmsystem, changes copied dataset behind frmproject (via raiseevent refreshsystemsdata) when frmsystem saved , closed. if user decides open frmsystem same system row again, populating database show out-of-date values. want frmsystem load values via copying dataset row in frmproject.
in light of this, added raiseevent trigger when frmsystem opens. idea read in system datarow frmproject.
however, appears raiseevent present in each form (referring each other) perhaps causing out of memory exception. application not load unless comment out code related populatesystemsdata , sendsystemdatatofrmsystem.
i have liked pass datarow parameter invokecommand subroutine - forms in database opened via subroutines in frmmain contains whole bunch of other code initialising forms etc etc don't want touch.
i thought passing datarow series of strings options() array in invokecommand(), mean values on frmsystem converted strings, wouldn't work.
i tried changing invokecommand constructor etc started getting complicated, , don't want break entire application!
i didn't know whether public function might it, need datarow passed when frmsystem opened, , it's frmmain code handles that.
i need datarow values @ time of invokecommand() subroutine execution (done frmmain).
any ideas how can solve this? here's cut-down version of forms code. in advance help.
public class frmproject private withevents frmsysteminst new frmsystem private sub ugsystem_afterentereditmode(byval sender system.object, byval e system.eventargs) handles ugsystem.afterentereditmode 'open system screen easy editing 'get active systemid ultragrid on frmproject dim intactivesystemid integer = ugsystem.activerow.cells("systemid").value dim intactivesiteid integer = ugsite.activerow.cells("siteid").value dim intsystemid integer = 0 each drt datarow in dsprojects1.tables("tbl_system").rows if drt.item("systemid") = intactivesystemid dim integer = drt.item("rowsaved") if drt.item("rowsaved") = 1 intsystemid = intactivesystemid end if end if next 'this opens frmsystem - executing frmsystem invokecommand(...) have liked pass datarow frmproject frmsystem here.... frmmdiparent.openform("frmsystem", intsystemid & "," & ugsystem.activerow.cells("systemreference").value & ", " & intactivesiteid & ", " & intprojectid, -1) 'get open frmsystem instance , set instance declared here on frmproject each f form in frmmdiparent.mdichildren if f.name.contains("frmsystem") frmsysteminst = f end if next end sub private sub frmsysteminst_refreshsystemsdata(byval d datarow) handles frmsysteminst.refreshsystemsdata 'jt 9/5/2013: refresh systems ultragrid data after frmsystem updated , closed each dr datarow in dsprojects1.tables("tbl_system").rows if dr.item("systemid") = d.item("systemid") each dca datacolumn in dr.table.columns each dcb datacolumn in d.table.columns if dca.columnname = dcb.columnname dr.item(dca.columnname) = d.item(dcb.columnname) end if next next end if next me.ugsystem.databind() 'if system rows exist, mark them "saved" - helps distinguish rows frmsystem whether row saved database (correct systemid), or it's not saved (using temp systemid row) each drt datarow in me.dsprojects1.tables("tbl_system").rows drt.item("rowsaved") = 1 next end sub private sub frmsysteminst_populatesystemsdata() handles frmsysteminst.populatesystemsdata 'jt 9/5/2013: send active system datarow frmproject frmsystem dim intactivesystemid integer = ugsystem.activerow.cells("systemid").value dim d datarow = nothing each drt datarow in dsprojects1.tables("tbl_system").rows if drt.item("systemid") = intactivesystemid d = drt end if next raiseevent sendsystemdatatofrmsystem(d) end sub public event sendsystemdatatofrmsystem(byval d datarow) public class frmsystem private withevents frmprojectinst new frmproject public sub invokecommand(byval sender object, byval e system.eventargs, optional byval options() string = nothing) implements smartdata.microgen.iaddin.iaddin.invokecommand 'get opened frmproject , set instance systems datarow. each f form in frmmdiparent.mdichildren if f.name.contains("frmproject") frmprojectinst = f end if next 'this fires event on frmproject active system row details. raiseevent populatesystemsdata() end sub 'this speaks frmproject run code updating system ultragrid public event refreshsystemsdata(byval d datarow) private sub frmprojectinst_sendsystemdatatofrmsystem(byval d datarow) handles frmprojectinst.sendsystemdatatofrmsystem 'copy system row frmproject frmsystem 'need add row dataset else we'll have nothing bind later dim rowtemp datarow = me.dssystembysystemid1.tables("get_systems_by_systemid").newrow me.dssystembysystemid1.tables("get_systems_by_systemid").rows.add(rowtemp) each dr datarow in dssystembysystemid1.tables("get_systems_by_systemid").rows if dr.item("systemid") = d.item("systemid") each dca datacolumn in dr.table.columns each dcb datacolumn in d.table.columns if dca.columnname = dcb.columnname dr.item(dca.columnname) = d.item(dcb.columnname) end if next next end if next end sub
that lot of code expect people review!
if create public method on frmsystem can call using frmsysteminst , pass in data after opening (datarow?) , plus pass reference calling form.
then using command button or form close event in frmsystem can call method on main form pass data back, using reference passed in.
Comments
Post a Comment