Click here to Skip to main content
15,896,269 members

to pass value from one textbox in one form to another textbox in another form

saranyasooraj asked:

Open original thread
hi all....please do help me...am stuck with this problem....

There are 2 forms.
In one form(form1),there are 3 textboxes(tb1,tb2,tb3) and corresponding to each there is a button..i.e: for tb1-btn1,tb2-btn2,and tb3-btn3
In second form(form2),there is one textbox(tb4) and one button(btn4)...
When i click on a button(say btn1)in form1,form2 should be displayed.and when some text is entered in textbox(tb4) and button(btn4) is clicked that text should be displayed in the textbox(tb1) in form1 which is corresponding to the button(btn1) clicked first.......like that for btn2 and btn3....The prob is what i enter in tb4 is displaying in all 3 textboxes(tb1,tb2,tb3)...
I dont want it like dat....What i want is....When btn1 is clicked value must be displayed only in tb1,similarly when btn2 is clicked value must be shown in tb2....and so for btn3...
This is in C#.net Windows Application
Here is the code i tried......


C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.Show();

        }

        internal void valuefromform2(string p)
        {
            textBox1.Text = p;
        }
}
}



C#
public partial class Form2 : Form
    {
        Form1 f1;
        public Form2()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (f1 == null)
                f1 = new Form1();
            f1.valuefromform2(textBox1.Text);
            f1.Show();
        }


    }



pls do help me....am stuck here...without this i cant go further in my project...pls pls...
Tags: C#, .NET (.NET4), Windows, Application

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900