473,651 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass Values between Forms in C# 2005

I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.

Thanks in advance.
Jun 27 '08 #1
14 3599
On Jun 20, 7:28 pm, Rick <R...@discussio ns.microsoft.co mwrote:
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.

Thanks in advance.
Do you want to pass data from Parent to Child... right???

-Cnu..
Jun 27 '08 #2
<Form A>
FormB b = new FormB(this.Text Box1.Text, this.TextBox2.T ext,
this.ComboBox1. SelectedIndex);
b.ShowDialog();
</FormA>

<FormB>
private string _LastName;
private string _FirstName;
private int _PersonTypeID;
public FormB(string LastName, string FirstName, int PersonTypeID) :
this()
{
_LastName = LastName;
_FirstName = FirstName;
_PersonTypeID = PersonTypeID;
}

public Form_Load(objec t sender, EventArgs e)
{
this.txtLastNam e = _LastName;
this.txtFirstNa me = _FirstName;
this.cboPersonT ype.SelectedInd ex = PersonTypeID;
}
</FormB>

If you need to retrieve the values back out of FormB (you're changing
data) then you can add properties and pull them out in FormA via
properties. What I do in my code at home is every single form control
has a "Changed" event that gets fired and with this event the new
value is taken via a new EventArg. In my case I wanted to know if the
data had been changed and if so then I wanted to update, but I didn't
want to update it no matter what.
Jun 27 '08 #3
On Jun 20, 7:28 pm, Rick <R...@discussio ns.microsoft.co mwrote:
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.

Thanks in advance.
Try the following code
public partial class FormA : Form
{
public FormA()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{

}

private void button1_Click(o bject sender, EventArgs e)
{
FormB formB = new FormB();

formB.data = this.textBox1.T ext.ToString();

formB.Show();

}
}
public partial class FormB : Form
{
public string data;

public FormB()
{
InitializeCompo nent();
}

private void FormB_Load(obje ct sender, EventArgs e)
{
MessageBox.Show (data);
}
}
Jun 27 '08 #4
Yes

"Duggi" wrote:
On Jun 20, 7:28 pm, Rick <R...@discussio ns.microsoft.co mwrote:
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.

Thanks in advance.

Do you want to pass data from Parent to Child... right???

-Cnu..
Jun 27 '08 #5
On Jun 20, 9:08 pm, Rick <R...@discussio ns.microsoft.co mwrote:
Yes

"Duggi" wrote:
On Jun 20, 7:28 pm, Rick <R...@discussio ns.microsoft.co mwrote:
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.
Thanks in advance.
Do you want to pass data from Parent to Child... right???
-Cnu..
Hope you got one example..

-Cnu
Jun 27 '08 #6
On Jun 20, 9:08 pm, Rick <R...@discussio ns.microsoft.co mwrote:
Yes

"Duggi" wrote:
On Jun 20, 7:28 pm, Rick <R...@discussio ns.microsoft.co mwrote:
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.
Thanks in advance.
Do you want to pass data from Parent to Child... right???
-Cnu..
Hope you got one example..

-Cnu
Jun 27 '08 #7
On Jun 20, 11:09*am, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
On Jun 20, 7:28 pm, Rick <R...@discussio ns.microsoft.co mwrote:
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. *My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.
Thanks in advance.

Try the following code

public partial class FormA : Form
* * {
* * * * public FormA()
* * * * {
* * * * * * InitializeCompo nent();
* * * * }

* * * * private void Form1_Load(obje ct sender, EventArgs e)
* * * * {

* * * * }

* * * * private void button1_Click(o bject sender, EventArgs e)
* * * * {
* * * * * * FormB formB = new FormB();

* * * * * * formB.data = this.textBox1.T ext.ToString();

* * * * * * formB.Show();

* * * * }
* * }

public partial class FormB : Form
* * {
* * * * public string data;

* * * * public FormB()
* * * * {
* * * * * * InitializeCompo nent();
* * * * }

* * * * private void FormB_Load(obje ct sender, EventArgs e)
* * * * {
* * * * * * MessageBox.Show (data);
* * * * }
* * }
I'm not generally a fan of the public member variable to pass data.
I've worked on too many VB6 projects where that's about the only way
to pass variables and its hell to maintain.
Jun 27 '08 #8
cfps.Christian,
I do not want to pass a series of strings like the example you provided:
FormB b = new FormB(this.Text Box1.Text, this.TextBox2.T ext,
this.ComboBox1. SelectedIndex)

I may have 50 or 100 fields on FormA and it amy not be the right approach.
Do you have an example of another way f doing it; the example Duggi has
provided would also work but it would require each field to be set to Public
and I would rather not do it.
"cfps.Christian " wrote:
On Jun 20, 11:09 am, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
On Jun 20, 7:28 pm, Rick <R...@discussio ns.microsoft.co mwrote:
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and click a button to bring up
FormB which needs to display values entered in FormA.
Thanks in advance.
Try the following code

public partial class FormA : Form
{
public FormA()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{

}

private void button1_Click(o bject sender, EventArgs e)
{
FormB formB = new FormB();

formB.data = this.textBox1.T ext.ToString();

formB.Show();

}
}

public partial class FormB : Form
{
public string data;

public FormB()
{
InitializeCompo nent();
}

private void FormB_Load(obje ct sender, EventArgs e)
{
MessageBox.Show (data);
}
}

I'm not generally a fan of the public member variable to pass data.
I've worked on too many VB6 projects where that's about the only way
to pass variables and its hell to maintain.
Jun 27 '08 #9
The critical issues are where your data is coming from in FormA and what you
are doing with it in FormB.

Until you determine that you cannot come up with a 'transfer' strategy.
"Rick" <Ri**@discussio ns.microsoft.co mwrote in message
news:E1******** *************** ***********@mic rosoft.com...
cfps.Christian,
I do not want to pass a series of strings like the example you provided:
FormB b = new FormB(this.Text Box1.Text, this.TextBox2.T ext,
this.ComboBox1. SelectedIndex)

I may have 50 or 100 fields on FormA and it amy not be the right approach.
Do you have an example of another way f doing it; the example Duggi has
provided would also work but it would require each field to be set to
Public
and I would rather not do it.
"cfps.Christian " wrote:
>On Jun 20, 11:09 am, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
On Jun 20, 7:28 pm, Rick <R...@discussio ns.microsoft.co mwrote:

I have seen examples of passing data from FormB to FormA (Parent To
Child)
but I need an example of passind data from FormA to FormB. My main
form is
FormA; I will enter some data in textboxes and click a button to
bring up
FormB which needs to display values entered in FormA.

Thanks in advance.

Try the following code

public partial class FormA : Form
{
public FormA()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{

}

private void button1_Click(o bject sender, EventArgs e)
{
FormB formB = new FormB();

formB.data = this.textBox1.T ext.ToString();

formB.Show();

}
}

public partial class FormB : Form
{
public string data;

public FormB()
{
InitializeCompo nent();
}

private void FormB_Load(obje ct sender, EventArgs e)
{
MessageBox.Show (data);
}
}

I'm not generally a fan of the public member variable to pass data.
I've worked on too many VB6 projects where that's about the only way
to pass variables and its hell to maintain.
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2116
by: VbUser25 | last post by:
hi.. i have a drop-down menu with a list of products.when i select any one product i open a popup displaying hte product categories in it.i then enter the no. of items i want.and finally when i click to the submit button i want to display a summary of selected item in the parent form.to make it more elaborate: i have 3 items in a drop-down menu and each item has further 10 different types of products.
1
2405
by: JM | last post by:
Hello, Using Access 2000 queries, you can reference(pass) form values directly using syntax like Forms!frmPaint!txtColor. I want to do a pass through query to SQL Server 2000, but I don't know how to pass the form values to SQL server without resorting to VB code. These canned queries populate other elements of the form, and that's another reason I don't want to write additional code. These queries were originally set up merely...
7
21612
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or PostgreSQL using ADO ? Is it possible to execute pass-through queries with parameters, using ADO...
8
3360
by: Brian F | last post by:
Exactly what the subject says. I have an ASP page that I want my C# windows application to open in Internet Explorer, and if possible have it send along a list of values from a list box. Thank you.
0
1097
by: **Developer** | last post by:
Would someone pass this on to MS and/or check to see it the problem persists in 2005? I don't have 2005 and do not know how to pass it on. Nor do I have the time to spend learning how unless it really easy. However, I spent much time on this and would like to see what I've learned put to use.
1
1783
by: colleen1980 | last post by:
There is a form where it ask the two dates and then run a query then report. Private Sub Command36_Click() DoCmd.OpenQuery "qryResultsReport" DoCmd.OpenReport "rpt_TopTen", acPreview, "", "" end sub qryResultsReport
2
3209
by: gumby | last post by:
I would like to call this stored procedure, but I am unable to pass parameters to the @Start and @End. Is thier a way to pass parameters to a pass through query from MS Access? SELECT COUNT(dbo.tblPersActionHistory.PersActionID) AS , .fn_FindStartPayPeriod(dbo.tblPersActionHistory.PersActionID, 2) AS FROM dbo.tblPersActionLog INNER JOIN
12
11073
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
6
1694
by: =?Utf-8?B?Unlhbg==?= | last post by:
I am trying to pass a value from a texbox in Form1 to a textbox in Form2 using properties in VS2005 but it doesn't work; please help (project is attached). Code for Game Class: using System; using System.Collections.Generic; using System.Text;
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7297
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.