0

I have been scouring the internet for days trying to find a way to pass an object to a form so that I can collect data edit the object then get the object back from the second form.

I have an object that is mostly made of text and the formatting of the text. I want to pass that to a second form so that I can fill in the values on the form and make changes to the values then read the object back out of the form and replace the object in the original with the new copy.

The main issue that I am having is passing the object. I have considered just writing the object to a tmp txt file then reading it into the form on the other side but there has to be some way to better pass a non-native data type relatively simply. I tried using databinding but failed to find an easy way to pass the whole object. Any help would be appreciated.

Tyler
  • 1

2 Answers2

0

I think these will be good for you.

How to pass data between two forms in C#

Passing Data Between Forms

  • Yes that is what I have been missing It seems i forgot to set my boxes and text area to be public so i could just grab the data I needed after I hide it. This should work. – Tyler Nov 11 '12 at 00:33
0

you can always pass the object while calling another form like:

form2 myform=new form2(myobject);
myform.Show();

This object can be recieved in another form (form2 here) as:

Initialize(myobject)
{
}
  • This works. Just FYI: Replacing the default constructor of a form with one that takes arguments will cause the Visual Studio designer to stop working. To get around this you can keep default constructor or wrap the default constructor with #if DEBUG so that you can still use the designer when compiling in debug but not when compiling in release. – ytoledano Nov 11 '12 at 13:26
  • @ytoledano: Why would the VS Designer stop working? It works just like any other code on my system and I have been using it for long. – Samarth Agarwal Nov 11 '12 at 13:39