Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old November 24th, 2008, 05:38 AM
Newbie
 
Join Date: Nov 2008
Posts: 13
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
  #2  
Old November 24th, 2008, 06:00 AM
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 691
Provided Answers: 1

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


Use static variables :
Expand|Select|Wrap|Line Numbers
  1.  public static  class myClass
  2.     {
  3.         public static string mytext;
  4.     }
  5.  
And initialize it on form2 and you can access it on form1...
  #3  
Old November 24th, 2008, 04:41 PM
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,569

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


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:
Expand|Select|Wrap|Line Numbers
  1. public string TextBoxText
  2. {
  3.   get { return textBox1.Text; }
  4. }
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:
Expand|Select|Wrap|Line Numbers
  1. Form2 f2 = new Form2();
  2. f2.ShowDialog();
  3. string txt = f2.TextBoxText;
Reply