C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to pass value from one form to another form


Posted Date: 09 Jun 2008    Resource Type: Code Snippets    Category: ADO.NET

Posted By: vijaybabu       Member Level: Silver
Rating:     Points: 10



The following code can be used if u want to display ur text box value in form2 from form1.


//following code for Form1


write this code in button1_click(object sender, eventargs e) // write in form1
{
Form2 frm2Obj = new Form2();
frm2Obj.form1TextBoxValue = textbox1.Text;
frm2Obj.show();
}


// following code for Form2


private string tempvalue;
public string form1TextBoxValue
{
get
{
return tempvalue;
}
set
{
tempvalue = value;
}
}

Now u can use tempvalue that consists of Form1 textBox value,anywhere in Form2.




Responses

Author: Kapil Dhawan    17 Jun 2008Member Level: Gold   Points : 2
Hello
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code is going to help lots of guys.
Ton Thanks to you
Regards,
Kapil



Author: UltimateRengan    04 Jul 2008Member Level: Diamond   Points : 1
hi,
Really nice.thanks for sharing your knowledge with us.


Author: Bindu Bujji    12 Jul 2008Member Level: Gold   Points : 2
Hi,
When i tried to use this, getting RTE "Error 1 'form1.Form2.txtform2' is inaccessible due to its protection level"

Here is my sample code:
FORM1
=======
private void button1_Click(object sender, EventArgs e)
{
//txtForm1 --> name of textbox in form1
//txtform2 --> name of textbox in form2
Form2 frm2obj = new Form2();
frm2obj.txtform2.value = txtForm1.Text;
frm2obj.Show();
}

------------

//FORM2

private string tempValue;

public string form1Textvalue
{
get
{return tempValue;}

set
{ tempValue = value;}
}


private void Form2_Load(object sender, EventArgs e)
{ txtform2.Text = tempValue; }

THANKS
Bindu



Author: Bindu Bujji    12 Jul 2008Member Level: Gold   Points : 2
Hi,
When i tried to use this, getting RTE "Error 1 'form1.Form2.txtform2' is inaccessible due to its protection level"

Here is my sample code:
FORM1
=======
private void button1_Click(object sender, EventArgs e)
{
//txtForm1 --> name of textbox in form1
//txtform2 --> name of textbox in form2
Form2 frm2obj = new Form2();
frm2obj.txtform2.value = txtForm1.Text;
frm2obj.Show();
}

------------

//FORM2

private string tempValue;

public string form1Textvalue
{
get
{return tempValue;}

set
{ tempValue = value;}
}


private void Form2_Load(object sender, EventArgs e)
{ txtform2.Text = tempValue; }

THANKS
Bindu



Author: Vidhya    18 Jul 2008Member Level: Gold   Points : 2
hi,

Really nice.thanks for sharing your knowledge with us.

You should create the instance to driving from to another form....

that is if you are pass the value from form1 to form2,
you should create an instance for form1 in form2.....

for example:

form1 f1=new form1();

here f1 is the instance...

using this instance f1, you can access the value or
pass the value from one form to another form...........

using this instance u can pass properties,classes,events,
functions......

u must modify those details which are passed by you,as public.....

unless you can't access those details even if u have an instance .....

make sure that.....


Regards,
Vidhya.....



Author: Siva Sankari    29 Jul 2008Member Level: Gold   Points : 0
Hi,

Nice code!.

Thanks For Sharing!

Sankari.


Author: UltimateRengan    29 Jul 2008Member Level: Diamond   Points : 0
hi,

nice one thanks for sharing ur knowledge


Author: sreenu    06 Aug 2008Member Level: Bronze   Points : 1
Hi,
I am new to c#.NET
Here, i am getting the value into form2.
And my doubt is..
How can we store these values in a string (in form2)and how can we use these string values in form2.

Thank You.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: stored procedure calling into application
Previous Resource: Where to Store Database Connection
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween mask

Contact Us    Privacy Policy    Terms Of Use