How to return data from one form to another

X

Xarky

Hi,

I have the main form, where from one of the methods, an instance
of another form is created. On the second form I have to fill some
data and be submitted by a button click. The data to be entered is to
be returned to the main form.

A sample of code of my problem.

// main Windows Form
private void EnterDataBtn_Click(object sender, System.EventArgs e)
{
SubForm x = new SubForm();
x.Show();
// here I need to get data that is filled on the sub form
// by doing "string = x.getData();", data entered is not being
// returned. Mainly because it not has been yet submitted
from
// other form.
// I need some sort of event or what?????
}

Please can someone help me out.

Thanks in Advance.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Declare some public properties in the second form from where you could get
your data back.


Cheers,
 
D

Daniel Pratt

Hi Xarky,

Xarky said:
Hi,

I have the main form, where from one of the methods, an instance
of another form is created. On the second form I have to fill some
data and be submitted by a button click. The data to be entered is to
be returned to the main form.

A sample of code of my problem.

// main Windows Form
private void EnterDataBtn_Click(object sender, System.EventArgs e)
{
SubForm x = new SubForm();
x.Show();
// here I need to get data that is filled on the sub form
// by doing "string = x.getData();", data entered is not being
// returned. Mainly because it not has been yet submitted
from
// other form.
// I need some sort of event or what?????
}

Please can someone help me out.

Thanks in Advance.

Besides what Ignacio said, you'll want to call Form.ShowDialog rather
than Form.Show. ShowDialog will not return (i.e. it will "wait") until the
form is closed.

Regards,
Daniel
 

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