473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can't pass data to another form.

Hi All,

I can't pass data to another form:
in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}

the form2 will close after button click, but the textbox1 of form1
doesn't change anything.

textbox1 of form1 already set to public.

Please advice.

Best regards,
Boki.

Jul 11 '07 #1
7 2552
On Jul 11, 10:24 am, Boki <bokit...@ms21.hinet.netwrote:
Hi All,

I can't pass data to another form:

in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}

the form2 will close after button click, but the textbox1 of form1
doesn't change anything.

textbox1 of form1 already set to public.

Please advice.

Best regards,
Boki.
I have resolved this issue.

I added the new form from the new button of toolbar.

It seems I have to add the new form from right mouse click of solution
explore.

Best regards,
Boki.

Jul 11 '07 #2
On Jul 11, 11:31 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 10:24 am, Boki <bokit...@ms21.hinet.netwrote:
Hi All,
I can't pass data to another form:
in form2:
private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}
the form2 will close after button click, but the textbox1 of form1
doesn't change anything.
textbox1 of form1 already set to public.
Please advice.
Best regards,
Boki.

I have resolved this issue.

I added the new form from the new button of toolbar.

It seems I have to add the new form from right mouse click of solution
explore.

Best regards,
Boki.
OK, sorry, it is not the root cause.

I got strange here, when I show form2 from form1, the string pass
well, but when I pass from form2, it never works.
/* this is form 1 code to show form 2*/
public void button1_Click(object sender, EventArgs e)
{
...

Form2 frm2 = new Form2();
frm2.textBox1.Text = "testing from form1"; /* this line
works well */
frm2.Show();
...

}

namespace Ring_Buffer_Test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Form1 frm = new Form1();
frm.textBox1.Text = "dsfsdf"; /* this line makes nothing
happen */
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}
}
}
Best regards,
Boki.

Jul 11 '07 #3
On Jul 11, 11:42 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 11:31 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 10:24 am, Boki <bokit...@ms21.hinet.netwrote:
Hi All,
I can't pass data to another form:
in form2:
private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}
the form2 will close after button click, but the textbox1 of form1
doesn't change anything.
textbox1 of form1 already set to public.
Please advice.
Best regards,
Boki.
I have resolved this issue.
I added the new form from the new button of toolbar.
It seems I have to add the new form from right mouse click of solution
explore.
Best regards,
Boki.

OK, sorry, it is not the root cause.

I got strange here, when I show form2 from form1, the string pass
well, but when I pass from form2, it never works.

/* this is form 1 code to show form 2*/
public void button1_Click(object sender, EventArgs e)
{
..

Form2 frm2 = new Form2();
frm2.textBox1.Text = "testing from form1"; /* this line
works well */
frm2.Show();
...

}

namespace Ring_Buffer_Test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Form1 frm = new Form1();
frm.textBox1.Text = "dsfsdf"; /* this line makes nothing
happen */
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}
}

}

Best regards,
Boki.
OK, new test result.

the code really create a new form, not the original form I was
using...

How to let it only do reference things....
Best regards,
Boki.

Jul 11 '07 #4
On Jul 11, 11:49 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 11:42 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 11:31 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 10:24 am, Boki <bokit...@ms21.hinet.netwrote:
Hi All,
I can't pass data to another form:
in form2:
private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}
the form2 will close after button click, but the textbox1 of form1
doesn't change anything.
textbox1 of form1 already set to public.
Please advice.
Best regards,
Boki.
I have resolved this issue.
I added the new form from the new button of toolbar.
It seems I have to add the new form from right mouse click of solution
explore.
Best regards,
Boki.
OK, sorry, it is not the root cause.
I got strange here, when I show form2 from form1, the string pass
well, but when I pass from form2, it never works.
/* this is form 1 code to show form 2*/
public void button1_Click(object sender, EventArgs e)
{
..
Form2 frm2 = new Form2();
frm2.textBox1.Text = "testing from form1"; /* this line
works well */
frm2.Show();
...
}
namespace Ring_Buffer_Test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 frm = new Form1();
frm.textBox1.Text = "dsfsdf"; /* this line makes nothing
happen */
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Best regards,
Boki.

OK, new test result.

the code really create a new form, not the original form I was
using...

How to let it only do reference things....

Best regards,
Boki.
Hi

I try this way in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1.update_msg_string(textBox1.Text.ToString());
}
and put this in form1:

public void update_msg_string(string msg_str)
{
textBox1.Text = msg_str;
}
No luck yet, ....

Boki.

Jul 11 '07 #5
When you have one form create another that requires data to be exchanged, it
is not advisable to directly manipulate controls on the other form.

There are a number of ways to pass info between forms

eg in form1 you may have

Form2 form2 = new Form2 ();
form2.Tag = someObject;
form2.Show();
and in form2_Shown you can have
MyObject o = (MyObject) Tag;

You can also set properties in Form2 eg

public string SetMyText
{
get { myControl.Text = value; }
}
and in Form1 you would have
form2.SetMyText = "aaaa";

or you can use functions, event handlers etc
"Boki" <bo******@ms21.hinet.netwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi All,

I can't pass data to another form:
in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}

the form2 will close after button click, but the textbox1 of form1
doesn't change anything.

textbox1 of form1 already set to public.

Please advice.

Best regards,
Boki.
Jul 11 '07 #6
It's very early in the morning here

set { myControl.Text = value; } // not 'get'

"Ian Semmel" <an****@rocketcomp.com.auwrote in message
news:#N**************@TK2MSFTNGP04.phx.gbl...
When you have one form create another that requires data to be exchanged,
it is not advisable to directly manipulate controls on the other form.

There are a number of ways to pass info between forms

eg in form1 you may have

Form2 form2 = new Form2 ();
form2.Tag = someObject;
form2.Show();
and in form2_Shown you can have
MyObject o = (MyObject) Tag;

You can also set properties in Form2 eg

public string SetMyText
{
get { myControl.Text = value; }
}
and in Form1 you would have
form2.SetMyText = "aaaa";

or you can use functions, event handlers etc
"Boki" <bo******@ms21.hinet.netwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
>Hi All,

I can't pass data to another form:
in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}

the form2 will close after button click, but the textbox1 of form1
doesn't change anything.

textbox1 of form1 already set to public.

Please advice.

Best regards,
Boki.
Jul 11 '07 #7
On Jul 12, 3:29 am, "Ian Semmel" <any...@rocketcomp.com.auwrote:
It's very early in the morning here

set { myControl.Text = value; } // not 'get'

"Ian Semmel" <any...@rocketcomp.com.auwrote in message

news:#N**************@TK2MSFTNGP04.phx.gbl...
When you have one form create another that requires data to be exchanged,
it is not advisable to directly manipulate controls on the other form.
There are a number of ways to pass info between forms
eg in form1 you may have
Form2 form2 = new Form2 ();
form2.Tag = someObject;
form2.Show();
and in form2_Shown you can have
MyObject o = (MyObject) Tag;
You can also set properties in Form2 eg
public string SetMyText
{
get { myControl.Text = value; }
}
and in Form1 you would have
form2.SetMyText = "aaaa";
or you can use functions, event handlers etc
"Boki" <bokit...@ms21.hinet.netwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi All,
I can't pass data to another form:
in form2:
private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}
the form2 will close after button click, but the textbox1 of form1
doesn't change anything.
textbox1 of form1 already set to public.
Please advice.
Best regards,
Boki.
Why got up so early today ?

Jul 12 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: vishal | last post by:
hi i am using get method to pass data from one form to another and my value may contain & symbol. so when this is case the value after & sign is truncated which is logically true. so what...
4
by: sparks | last post by:
We have a database that reads in and formats raw data. We were using queries to format the data per person and outputing reports. The other database has the persons personal information. I changed...
3
by: Lyn | last post by:
Hi, I have been experiencing a problem passing a LIKE statement in the WHERE argument of a DoCmd.Openform statement. I have posted that issue separately. However, in an attempt to work around...
3
by: Chung | last post by:
Hi all, I have used the following code for doing the form submission. I don't think this is a right way to submit a from to a new aspx page because I need to add a dummy form in between. Could...
4
by: tom | last post by:
Hi Experts, I want to pass the selectedDate value from my calender form to another web form or a web user control. Could you please show me how to do this? Thanks in advance.
2
by: KFactor | last post by:
Is it possible to pass form variables to a page on another server using response.redirect? Or is there a secure way of passing sensitive information from one site to another such as a userID? ...
2
by: c676228 | last post by:
Hi, This is my first time to post asp.net question on this forum. I have a question for "How to pass the first form value to the next form" I have enrollinfo.aspx form which look like as follow:...
17
by: Rabbit | last post by:
Hi, On my 1st page, i have a function which gets a new ID value and need to transfer to another immediately. which I want to get in 2nd page using Request.form("txtID"), but doesn't work, the...
14
by: =?Utf-8?B?Umljaw==?= | last post by:
I have seen examples of passing data from FormB to FormA (Parent To Child) but I need an example of passind data from FormA to FormB. My main form is FormA; I will enter some data in textboxes and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.