Click to See Complete Forum and Search --> : Maintain data between Forms


ccfriend
February 17th, 2006, 12:03 PM
Hi

I have one main Form1 which contains a button that call ShowDialog () to show a new Form2. In this new Form2 I have a Label, a Textbox and a Button. I write something in Textbox and that is copied in the Label after I push the Button. When I close the Form2 and reopen it, the text in Label has been lost (of course). The more simple solution is to store the text in a static string and Load it in Label when Form2 loads.

Is this the best way to maintain data between forms, by using static fields?
If I have more complex Controls like a TreeView I must save and store all the data in static variables?

Is there any other way to handle it? (it would be great if a .NET class can handle this automatically)


Thanks!!!!!!!!!!!

Sahir
February 19th, 2006, 07:11 AM
Is this the best way to maintain data between forms, by using static fields? Not sure if it's the best, but it is a reasonably good way.

jmcilhinney
February 19th, 2006, 06:30 PM
.NET classes can "handle this automatically" and you already do it all the time. You have no doubt set properties and passed paraneters to methods, including constructors. That's all you have to do to get data into an object. I strongly suggest that you read this three part tutorial: http://www.devcity.net/Articles/94/1/multipleforms.aspx

kolluru
February 19th, 2006, 11:13 PM
Hai,

Maintain ur lable info into a local variable and send to form1 on closing using as an argument of a function.

Again when opening Form2 Send through an overloaded constructor.


Kolluru