1,105,332 Community Members

Passing Variable to another form

Member Avatar
love_dude1984
Junior Poster in Training
92 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

hi...

i just wanted to know how we can access the variable of 1 form to another form.as far as i know, ther is no session management concept in C#.

for ex., i want to access my login id into the next form. then what will be the procedure to do so?

thnks for the help..

Member Avatar
afaque_khan1
Newbie Poster
3 posts since Feb 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

it is simple.... all you need to do is to create a private variable in you 2nd from then assign a public interface in the following way

private string a;// create a property
public string IntefaceForA
{
get
{
return a;
}
set
{
a = value;
}
}

then in the form from where you need to pass values
you need to assign the value to that variable.

form2 obj = new form2();
obj.InterFaceForA = "loginID";
obj.show();

}

now you can access the value any where in your 2nd form;

I hope this solves your problem..

Member Avatar
ddanbe
Posting Expert
5,355 posts since Oct 2008
Reputation Points: 2,066 [?]
Q&As Helped to Solve: 908 [?]
Skill Endorsements: 46 [?]
Featured
 
0
 

If you did a search here, you would probably have found this snippet : http://www.daniweb.com/code/snippet1008.html

Member Avatar
LizR
Posting Virtuoso
1,735 posts since Aug 2008
Reputation Points: 171 [?]
Q&As Helped to Solve: 190 [?]
Skill Endorsements: 4 [?]
 
0
 

Or how to pass it when making/opening the other form

Member Avatar
afaque_khan1
Newbie Poster
3 posts since Feb 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

obj.show() will show/open the other form.... so you have to assigne that before doing this as i have shown previously

Member Avatar
LizR
Posting Virtuoso
1,735 posts since Aug 2008
Reputation Points: 171 [?]
Q&As Helped to Solve: 190 [?]
Skill Endorsements: 4 [?]
 
0
 

Or, override the show function with a variable to make it so you pass the required variables with it.

Member Avatar
JerryShaw
Posting Pro in Training
467 posts since Nov 2006
Reputation Points: 46 [?]
Q&As Helped to Solve: 75 [?]
Skill Endorsements: 0 [?]
 
0
 

Or simply post the variables in the constructor.
// Jerry

Member Avatar
DangerDev
Posting Pro in Training
485 posts since Jan 2008
Reputation Points: 107 [?]
Q&As Helped to Solve: 59 [?]
Skill Endorsements: 0 [?]
 
1
 

Or, create a constructor in Form2 which take loginId String as parameter.

Member Avatar
rodrigobraz
Newbie Poster
1 post since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks! it really helped :D

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article