How to transfer a variable from a Form to an other ?

  • Thread starter Thread starter rom15becs
  • Start date Start date
R

rom15becs

Hi everyone,
I'm working on a project that uses 2 forms : one to select an object
and one other to display its attributes.
I mean that in the first one I select an object (from a ComboBox),
then I open a new form where I could see all the properties of that
object.

The problem is that I can't find a way to "transfer" my SelectedItem
from my selection Form to the other Form.

I tried to declare a private attribute with some accessors like that:
=====================================================
public partial class TheForm : Form
{
private MyObject _theObject;
public MyObject theObject
{
get
{
return this._theObject;
}
set
{
this._theObject = value;
}
}
private void TheForm_Load(object sender, EventArgs e)
{
============================================
But that generate accessibility errors on compilation.
Does anyone can help me Please ?

Regards

Romain KEIRSEBILCK
 
Hi everyone,
I'm working on a project that uses 2 forms : one to select an object
and one other to display its attributes.
I mean that in the first one I select an object (from a ComboBox),
then I open a new form where I could see all the properties of that
object.

The problem is that I can't find a way to "transfer" my SelectedItem
from my selection Form to the other Form.

I tried to declare a private attribute with some accessors like that:

But that generate accessibility errors on compilation.
Does anyone can help me Please ?

The accessibility error would probably be due to MyObject being
declared as an internal class. Either make it public, or make the
property internal too.

Jon
 
Hi everyone,
I'm working on a project that uses 2 forms : one to select an object
and one other to display its attributes.
I mean that in the first one I select an object (from a ComboBox),
then I open a new form where I could see all the properties of that
object.

The problem is that I can't find a way to "transfer" my SelectedItem
from my selection Form to the other Form.

I tried to declare a private attribute with some accessors like that:
=====================================================
public partial class TheForm : Form
{
private MyObject _theObject;
public MyObject theObject
{
get
{
return this._theObject;
}
set
{
this._theObject = value;
}
}
private void TheForm_Load(object sender, EventArgs e)
{
============================================
But that generate accessibility errors on compilation.
Does anyone can help me Please ?

Regards

Romain KEIRSEBILCK

Define a property in the form TheForm. Before closing the form, set
the property's value to the control in question. When the form closes,
the property will be available to the form that opened TheForm.
 
Waaaaa... Guess what its finally working !!
Thanks a lot
I didn't know the internal stuff, I learned something today..

See you
Best Regards
 

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

Back
Top