By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,473 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,473 IT Pros & Developers. It's quick & easy.

communcation between forms - give back data from form2 to parent-form1

P: n/a
hello,

i'm working in VB.NET (2005) and i've got the following problem:

i've got 2 forms. (formMain and formSeach). In formMain i've got a
function to open formSeach.

Dim frmSeach as new formSeach
frmSeach.ShowDialog()

in formSeach there is the possibility to seach for some data and, when
the users clicks on OK, formSeach will close and the data will be used
in formMain.

The problem is, i don't know how to get the data from formSeach into
FormSeach.

I thought about using pointers but VB.NET doesn't support pointers as
far as i know.

Question: Whats the best way to give data back from a form to the
parent form??

Jul 20 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jul 20, 3:22 am, "unknown;" <unknown1...@gmail.comwrote:
hello,

i'm working in VB.NET (2005) and i've got the following problem:

i've got 2 forms. (formMain and formSeach). In formMain i've got a
function to open formSeach.

Dim frmSeach as new formSeach
frmSeach.ShowDialog()

in formSeach there is the possibility to seach for some data and, when
the users clicks on OK, formSeach will close and the data will be used
in formMain.

The problem is, i don't know how to get the data from formSeach into
FormSeach.

I thought about using pointers but VB.NET doesn't support pointers as
far as i know.

Question: Whats the best way to give data back from a form to the
parent form??
I depends, are opening the second form modally or not?

If the second form is modal, the simplest way is to obtain the values
from the instance of the second form you created. In the second form
you need to simply expose the necessary fields via properties.

If it's not opened modally, the best (imo) way is to raise a custom
event from the second form. The process would go like this:

In Form1:

Instantiate Form2
Subscribe to Form2's event
When Form2 closes, retrieve value(s) from the ...EventArgs Argument
in the event handler

In Form2:

Raise your custom event when the user clicks OK.

If you need sample code on how to create the custom event, let me know
and I'll be happy to post it for you.

Thanks,

Seth Rowe

Jul 20 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.