How to: Pass a variable value of a form to another form?

  • Thread starter [ F e r n a n d o L o p e s ]
  • Start date
F

[ F e r n a n d o L o p e s ]

Hello ALL,
I have two forms (frmCustomers, frmOpenCustomers)
In the frmOpenCustomers, i have a DataGrid fill with the Customers name.
I show the frmOpenCustomers form from the frmCustomers form like that:

frmOpenCustomers opCust = new frmOpenCustomers();
opCust.ShowDialog();

After I click the row of the customers grid in the opCust form, I need to
close this and show the name of the customer in a public TextBox in the
frmCustomers form.
But nothing appears.

What Am doing wrong?

Thanks in advance.
Sorry my English.

Fernando Lopes
Brazil
 
K

Kevin McNeish [C# MVP]

Fernando,
After I click the row of the customers grid in the opCust form, I need to
close this and show the name of the customer in a public TextBox in the
frmCustomers form.

There's a few ways you can solve this problem. Here's one way:

1. Create an application-level static property called CurrentCustomer
2. When the user launches the modal dialog, clear this property
3. When the user selects a customer in the modal form, store the value in
this static property
4. When the modal form is closed and the calling form continues execution,
retrieve the selected value from this static property

Regards,
Kevin McNeish
C# MVP
Chief Software Architect, Mere Mortals .NET Framework
www.oakleafsd.com
 

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