Solved

Display value from Child form to parent TextBox

Posted on 2008-09-29
4
401 Views
Last Modified: 2013-12-17
Hi,
I have winForm (form1 and form2)
On Form1 I have Textbox (txtBox1 and form2  txtbox2 )
On click of button I load form2  ie   form2.showDialog()   ..I have to display value entered in Txtbox2 in form1 textbox (txtbox1)
NOTE : Form1 would be open first.. (How can i reload the form1 back again to show the txtBox2 value)
0
Comment
Question by:dotnet0824
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Jai S
ID: 22595681
say you have a button btnSendValuesToForm1...
here will be the code to displau the textbox2 value in textbox1 of form1

onclick="javascript:parent.document.getElementById('txtbox1').value = document.getElementById('txtbox2').value;window.close();return false;"

if its a server side control then instead of onclick you put onClientClick...which will generate teh onclick event for that button...
0
 

Author Comment

by:dotnet0824
ID: 22595704
Hi, This is windowsForm applicatoin.... Pls I am looking for Code
0
 
LVL 14

Accepted Solution

by:
Jai S earned 500 total points
ID: 22595901
oops sorry...
here it is...

//FORM 1 button click event
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();
            frm2.ShowDialog();
            textBox1.Text = frm2.textvalue;
        }
 
//Form2 button click event and global variable for 
        public string textvalue;
        public Form2()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            textvalue = textBox1.Text;
            this.DialogResult = DialogResult.OK;
 
        }

Open in new window

0
 
LVL 11

Expert Comment

by:ladarling
ID: 22596923
The click event for your Form2 button should be somthing like:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form1.TextBox1.Text = Me.TextBox2.Text
Me.Close()
End Sub
You can refer to Form1, in this case, by its class name in VB.NET.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question