how to get tha data from form1 to form2 and again in form 1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pnalla
    New Member
    • Nov 2008
    • 13

    how to get tha data from form1 to form2 and again in form 1

    hi,
    I oppend first FORM-1 , in FORM-1 click a button and opens FORM-2,
    I Entered some text in text box of Form-2, I need the text in FORM -1 again
    How to achive this gaol. please help me with sample code........... ..

    thanks
    prasad
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Use static variables :
    Code:
     public static  class myClass
        {
            public static string mytext;
        }
    And initialize it on form2 and you can access it on form1...

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      Static isn't really the way to go here. This is what Properties were made for.

      You need to have a public property set in Form2:
      Code:
      public string TextBoxText
      {
        get { return textBox1.Text; }
      }
      renaming it and changing the name of the textbox as necessary.

      Then you should be able to get the information from it in form1, after you call it:
      Code:
      Form2 f2 = new Form2();
      f2.ShowDialog();
      string txt = f2.TextBoxText;

      Comment

      Working...