Connecting Tech Pros Worldwide Help | Site Map

pass the value in a textbox from form1 to the textbox in form3.

  #1  
Old July 23rd, 2008, 10:47 AM
Newbie
 
Join Date: Jul 2008
Posts: 22
i hav 3 forms.After clicking a button on form1 it shows form2 n similarly after clicking form2 ,form3 appears.i want to hav the value in a textbox in form3 from a textbox in form1.
  #2  
Old July 23rd, 2008, 11:05 AM
Lives Here
 
Join Date: Sep 2006
Posts: 12,085

re: pass the value in a textbox from form1 to the textbox in form3.


When the button on Form1 is clicked, pass the textbox's value to Form2 through Form2's constructor.
  #3  
Old July 23rd, 2008, 06:06 PM
Newbie
 
Join Date: Jul 2008
Posts: 22

re: pass the value in a textbox from form1 to the textbox in form3.


I know how to pass the value to Form2,which is directly called by Form1.
But i want to know how to pass value to Form3 which is not directly called by Form1.Form3 is called by Form2,and Form2 does not uses the value that is required by Form3(the value which is passed from form1 to form3).

Form1 has a button which on a click opens Form2 and Form2 also has a button which on click opens Form3.I want to pass the value in a textbox in Form1 to the textbox in Form3.The main problem is that Form3 is not directly called by Form1 in this case i want to know how to pass the values b/w these forms.
hope now my ques is clear.plzz give the solution.
  #4  
Old July 23rd, 2008, 06:15 PM
Member
 
Join Date: Aug 2006
Location: USA
Posts: 92

re: pass the value in a textbox from form1 to the textbox in form3.


hi,

The answer is already given by r035198x .

You pass the value from form1 to form2 and from form2 to form3.

Send the value through the form2s constructor and store the value in some global variable in form2 and when u call form3 send it to this constructor and thats done you got the value in form3.
  #5  
Old July 24th, 2008, 10:59 AM
Newbie
 
Join Date: Jul 2008
Location: Philippines
Posts: 12

re: pass the value in a textbox from form1 to the textbox in form3.


Pass the value of textbox in the constructor while calling form2. store the value in a global variable inside form2, eventhough it is not used, and pass the value on form3 when calling it by using that variable as parameter for the constructor.
  #6  
Old July 25th, 2008, 12:40 PM
Newbie
 
Join Date: Jul 2008
Posts: 22

re: pass the value in a textbox from form1 to the textbox in form3.


thanks its working.
.................................................. .................................................. ....
  #7  
Old July 25th, 2008, 01:27 PM
Lives Here
 
Join Date: Sep 2006
Posts: 12,085

re: pass the value in a textbox from form1 to the textbox in form3.


Quote:
Originally Posted by Sharma Neha
thanks its working.
.................................................. .................................................. ....
Welcome. Reading a tutorial on how to use classes in C# will clarify further.
  #8  
Old July 25th, 2008, 01:30 PM
markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Posts: 543
Provided Answers: 2

re: pass the value in a textbox from form1 to the textbox in form3.


Quote:
Originally Posted by r035198x
Welcome. Reading a tutorial on how to use classes in C# will clarify further.
A static class is a nice way to do this.

i.e. - information.cs

then a public variable in there

get:{}
set:{}

methods for that value.

then when you call form 3 look for Information.myValue;
  #9  
Old July 25th, 2008, 01:36 PM
Lives Here
 
Join Date: Sep 2006
Posts: 12,085

re: pass the value in a textbox from form1 to the textbox in form3.


Quote:
Originally Posted by markmcgookin
A static class is a nice way to do this.

i.e. - information.cs

then a public variable in there

get:{}
set:{}

methods for that value.

then when you call form 3 look for Information.myValue;
If the variable is not required to be an instance variable by the design then that would also work. Many instance variables have made been made static incorrectly just to get at them as quickly as possible when writing code though.
  #10  
Old July 25th, 2008, 05:09 PM
joedeene's Avatar
Site Addict
 
Join Date: Jul 2008
Location: US of A
Posts: 587

re: pass the value in a textbox from form1 to the textbox in form3.


in VB couldnt you just do something like

Expand|Select|Wrap|Line Numbers
  1. private shared form1txtvalue as string 'or integer or whatever the value is
  2. 'and then set the value when the button is clicked
  3.  


and then in form3 just use

Expand|Select|Wrap|Line Numbers
  1. textbox1.text=form1txtvalue
wouldnt that work ?
  #11  
Old July 25th, 2008, 05:15 PM
TRScheel's Avatar
Expert
 
Join Date: Apr 2007
Location: Iowa
Posts: 624

re: pass the value in a textbox from form1 to the textbox in form3.


Quote:
Originally Posted by joedeene
in VB couldnt you just do something like

Expand|Select|Wrap|Line Numbers
  1. private shared form1txtvalue as string 'or integer or whatever the value is
  2. 'and then set the value when the button is clicked
  3.  


and then in form3 just use

Expand|Select|Wrap|Line Numbers
  1. textbox1.text=form1txtvalue
wouldnt that work ?

Only if the variable isn't changed before being requested. It should really be passed along through the stack if it can be.
Reply