vb.net - How do I use the Tag property with forms and code in VB 2012? -
i writing program using database customers , technicians. main form (customerincidents) has toolstripbutton opens different form (searchbystate) user inputs state code , looks incidents.
if user clicks 1 of datagrid cells want customers information stored in tag when form closed using ok button show in main form (customerincidents).
edited 03/11/14 12:21pm
the problem in main form. when click ok button in second form tries convert dialogresult button string. can't figure out how fix it.
customer form (main form) opens secondary form
private sub btnopenstate_click(byval sender system.object, byval e system.eventargs) handles btnopenstate.click dim frmsearchstate new findcustomer ----->>dim selectedbutton dialogresult = frmsearchstate.showdialog() if selectedbutton = windows.forms.dialogresult.ok customeridtoolstriptextbox.text = frmsearchstate.tag.tostring end if'
search state form (secondary form) or "child form"
private sub btnok_click(message string, byval e datagridviewcelleventargs) handles btnok.click message = customersdatagridview.rows(e.rowindex).cells(e.columnindex).value.tostring me.tag = message me.dialogresult = dialogresult.ok end sub
the click event button not have datagridviewcelleventargs parameter, , throw exception when try use it.
you don't need use tag property since can create own property.
in child form, create property called gridvalue:
private sub btnok_click(sender object, e eventargs) handles btnok.click if dgv.currentcell nothing orelse dgv.currentcell.value nothing messagebox.show("a cell needs selected.") else me.dialogresult = dialogresult.ok end if end sub public readonly property gridvalue string return dgv.currentcell.value.tostring end end property
in parent form, can access information:
using frmsearchstate new findcustomer if frmsearchstate.showdialog(me) = dialogresult.ok customeridtoolstriptextbox.text = frmsearchstate.gridvalue end if end using
Comments
Post a Comment