Passing Data from search form back to main form

I have a vb.net Windows  app that has 2 forms: Main and search.  The form "main" is using a tab control with 7 active tabs.  An instance of the form "Search" can be created from many points.  The search pulls data from a customer table into a grid.  User then selects the one row and populates controls in 2-3 tabs on mainform, and closes leaving the main form as only one open.  My questions:

How can I populate the controls on the mainform from the search form?

What envent back on the mainform is a good one to do anything from that will fire when the search form closes?

Can you give me an example of what to do?
garyinmiami2003Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
What .NET version are you using?

Bob
0
garyinmiami2003Author Commented:
2003
0
Bob LearnedCommented:
To detect a form closing/closed, monitor the Closing or the Closed event.  In 2005 these events were changed to FormClosing and FormClosed (so you see why I ask about version).

When you open the search form, do you set owner:

   frmSearch.Show(Owner:=Me)

Bob
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

garyinmiami2003Author Commented:
Dim frm As New Form2


        frm.ShowDialog(Me)
0
PockyMasterCommented:
You don't need to close the search form from your main form , you can either close it after your user is done with it (he clicks a close button) or you close it yourself after you copied your data.

When you need it, just call mySearchForm.Show

Provide your searchForm with a delegate pointing at a datafill method in your mainform

So in your searchForm

Public Delegate Sub dlSetMyFields(Field1 as string, Field2 as string, Field3 as string)
private _dlSetMyFields as dlSetMyFields

Modify your searchform constructor

Public sub New (SetFields as dlSetMyFields)
_dlSetMyFields = Setfields
end sub

Now when you are done and click your close button e.g.

just _dlSetMyFields(txtField1.Text, txtField2.text, txtField3.Text)

where txtfield1 is e.g. a textfield in your searchForm.

this will call a function in your main form actually

Now in your mainForm create your searchForm

private _frmSearch as new frmSearch(AddressOf SetMyFields)

Now create a method SetMyFields in your mainform:

Private Sub SetMyFields(txtField1.Text, txtField2.text, txtField3.Text)

implement it, and you are a happy person (or not ) :D

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
Do this in Form2 to get a reference to the owner form:

   Dim mainForm As frmMain = CType(Me.Owner, frmMain)

Bob
0
garyinmiami2003Author Commented:
I am already a happy person.  Looks like I may have a follow up.  I'm doing something wrong in implementation.  Many thanks to you(you both) for your help
0
PockyMasterCommented:
You're welcome .. but what's your implementation problem?
0
garyinmiami2003Author Commented:
Let me fiddle with it a little, Learn what I can...Maybe it will clear up for me.  If not I'll add a comment
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.