Solved

Display value from Child form to parent TextBox

Posted on 2008-09-29
4
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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