CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    40

    Maintain data between Forms

    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!!!!!!!!!!!

  2. #2
    Join Date
    Aug 2002
    Location
    Kerala
    Posts
    1,183

    Re: Maintain data between Forms

    Quote Originally Posted by ccfriend
    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.

  3. #3
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Maintain data between Forms

    .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
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

  4. #4
    Join Date
    Aug 2005
    Posts
    44

    Re: Maintain data between Forms

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured