Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Values from modal form to parent form vb.net

I am trying to pass information to parent form from modal form in vb.net winforms application.

1.) I created a copy of a form and displayed it using following code.

dim f=new frmParent()
f.show()

2.) Depending on conditions a button on frmParent opens a modal child form and asks for some informations. I used following code for that:

dim f = new ChildForm()
f.showDialog()

Both code works fine. When user press saves in child form i need to close childForm and use the user types values in parent form. I know how to close the childform but not sure how to pass info from childform to parent form.

like image 430
KoolKabin Avatar asked Feb 23 '23 07:02

KoolKabin


1 Answers

Have a public property on your childForm

Public Property MyData As MyType

Then when you show the form you can do

dim f as new ChildForm()

If f.showDialog = DialogResult.OK Then
   Data = f.MyData()
End if

If you need to allow them to be able to edit that data again then you might also want to consider passing in the Data to the constructor of the dialog.

like image 191
David Steele Avatar answered Feb 25 '23 20:02

David Steele