Solved

Display value from Child form to parent TextBox

Posted on 2008-09-29
4
422 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

617 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