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

U

unknown;

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

rowe_newsgroups

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top