Thursday, May 22, 2008 9:47 AMCurrently, I am doing a project. I don't know how to pass a value from one windows form to another
windows form using c#.net. Suppose, I have two form: parent form and child form. Parent form consists of a
combo box & button and I want to pass selected item of combo box to my child form and that item will be
showing in a textbox of child form.
I want immediate help regarding this problem.
Note: I am using MS visual 2005
Thursday, May 22, 2008 9:58 AM
pretty simple. pass in the values you want to pass via the constructor for your child form then set the values in the global variables in that form so your form can access them. Here is an example:
//this is the main form. we are doing this code:
Form2 child = new Form2("Bob", 22); //2 parameters being passed via constructor
//this is Form2. Modify the constructor:
public void Form2(string name, int age)
InitializeComponent(); //this is default
//set the values coming in to the global variables so we can access it in this form throughout the life of this form
this._name = name;
this._age = age;
//declare these globally in form2 (after the form class decleration)
private string _name = String.Empty;
private int _age;
and thats it. Now say from Button1 on Form2, we want to read those values. Do this:
MessageBox.Show(this._name + " " + this._age.ToString()); //should show "Bob 22" since we passed "Bob" and 22 from the parent form
Tuesday, August 04, 2009 10:10 AMHi,
I have similar question. I am working on project that has 3 child forms and MDI PARENT. In my form1 i have file upload button that captures filepath.In my 2nd form i have few user selected values(strings). My third form has a button which when clicked should actualy take the filepath from first form and values from 2nd form and do modifications to the file. how should i proceed. Your replies will be appreciated.
Tuesday, August 04, 2009 1:27 PM
The best way to proceed would be to start a new thread/question of your own.
Mark the best replies as answers. "Fooling computers since 1971."
Saturday, December 26, 2009 10:16 AMahmedilyas
Thanks a ton....
Tuesday, September 21, 2010 2:23 AMthis looks like it would help me, i got the same prob. Gonna try this out.
Friday, January 27, 2012 12:31 PM
worked for me. Just what I needed, thanks
- Proposed As Answer by nmaheshgoud Monday, January 30, 2012 8:08 AM
Thursday, March 01, 2012 10:25 AMThanks. It helps a lot.
Friday, March 02, 2012 5:58 PM
This is a Visual Basic forum, NOT a C# forum!
Please direct your questions to the proper forum.
Wednesday, October 10, 2012 7:43 AM
if these 2 forms are MDI Childs , normal Calling of any MDI CHILD Form uses the Default Constructor , i tried to add Parametrized Constructor, on execution , i tried to call one MDI Child to another , its calling twice.
my Code problem:
In Form - A : if Call Form B as : FormB objB=new FormB(this); // this calling on RadioButton Checked
it calling FormB , then im returning a String Value to FormA. it returning string Value to FormA.
it works fine , the values passing are getting but the FormB executes Twice how?. this is Problem.
Thanks in Advance.
Saturday, October 20, 2012 3:14 PMHi check the below link. this will help you.