Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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?
0
garyinmiami2003
Asked:
garyinmiami2003
  • 4
  • 3
  • 2
3 Solutions
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now