Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 24th, 2008, 04:38 AM
Newbie
 
Join Date: Nov 2008
Posts: 13
Default 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
Reply
  #2  
Old November 24th, 2008, 05:00 AM
PRR's Avatar
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: The Matrix
Posts: 601
Default

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...
Reply
  #3  
Old November 24th, 2008, 03:41 PM
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Age: 24
Posts: 2,486
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.