473,508 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filling textbox in parent form from child form

I have Form1 and Form2 (which is inherited from Form1), and I created a
button in Form2 that will fill up a textbox in Form1. What code would do
that?

I tried the simplest way:

//from child form in button2 clicked event:

textbox1.Text = "Hello";

but it gave a protection level error since the parent textbox is private. I
then changed it to public but it only changes the textbox contents in the
second form. I don't mind if it changes both textboxes , but I need to be
able to modify the contents of the textbox in the parent form.

Anyone know how to do this?

Thanks in advance.

Nov 15 '05 #1
3 3932

Hi Omar,

I think you will show your form2 in the form1,
So you can pass the reference of the form1 to the form2 through the
constructor of the form2.
Then, in class form2, you got the reference of the form1, you can invoke
its textbox control.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Omar Llanos" <None>
| From: "Omar Llanos" <None>
| Subject: Filling textbox in parent form from child form
| Date: Thu, 25 Sep 2003 21:56:44 -0500
| Lines: 21
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uq**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: cvx-ppp-66-50-133-170.coqui.net 66.50.133.170
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:187455
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I have Form1 and Form2 (which is inherited from Form1), and I created a
| button in Form2 that will fill up a textbox in Form1. What code would do
| that?
|
| I tried the simplest way:
|
| //from child form in button2 clicked event:
|
| textbox1.Text = "Hello";
|
| but it gave a protection level error since the parent textbox is private.
I
| then changed it to public but it only changes the textbox contents in the
| second form. I don't mind if it changes both textboxes , but I need to be
| able to modify the contents of the textbox in the parent form.
|
| Anyone know how to do this?
|
| Thanks in advance.
|
|
|
|

Nov 15 '05 #2
Thanks for the info.
In my case, I open both at the same time through a mainMenu in my MDI
container.

This is the code in the mainMenu:
frm_AddNewProduct frm_myProducts = new frm_AddNewProduct(); //the parent

frm_myProducts.MdiParent = this;

frm_myProducts.Show();

Form2 form2 = new Form2(); //Form2 inherited from frm_myProducts

test.MdiParent = this;

test.Show();

How would I change this code (the reference part you mentioned) so I can
manipulate any control in frm_AddNewProduct from Form2 (inherited from
frm_AddNewProduct).

Thanks again,

Omar

"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:Sr**************@cpmsftngxa06.phx.gbl...

Hi Omar,

I think you will show your form2 in the form1,
So you can pass the reference of the form1 to the form2 through the
constructor of the form2.
Then, in class form2, you got the reference of the form1, you can invoke
its textbox control.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Omar Llanos" <None>
| From: "Omar Llanos" <None>
| Subject: Filling textbox in parent form from child form
| Date: Thu, 25 Sep 2003 21:56:44 -0500
| Lines: 21
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uq**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: cvx-ppp-66-50-133-170.coqui.net 66.50.133.170
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:187455 | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I have Form1 and Form2 (which is inherited from Form1), and I created a
| button in Form2 that will fill up a textbox in Form1. What code would do | that?
|
| I tried the simplest way:
|
| //from child form in button2 clicked event:
|
| textbox1.Text = "Hello";
|
| but it gave a protection level error since the parent textbox is private. I
| then changed it to public but it only changes the textbox contents in the | second form. I don't mind if it changes both textboxes , but I need to be | able to modify the contents of the textbox in the parent form.
|
| Anyone know how to do this?
|
| Thanks in advance.
|
|
|
|

Nov 15 '05 #3

Hi Omar,

The logic in your code is not very clear.
As you said, the frm_myProducts is a parent form, but what does
"frm_myProducts.MdiParent = this;" mean?
What is "test"?

For your problem, you should create a overloading constructor in class
Form2
which takes a form1 reference parameter.
Then you can do pass the reference of form1 like this:
Form2 form2 = new Form2(frm_myProducts);

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Omar Llanos" <None>
| From: "Omar Llanos" <None>
| References: <uq**************@TK2MSFTNGP12.phx.gbl>
<Sr**************@cpmsftngxa06.phx.gbl>
| Subject: Re: Filling textbox in parent form from child form
| Date: Sat, 27 Sep 2003 00:32:34 -0500
| Lines: 93
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <ue*************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 66-50-71-192.prtc.net 66.50.71.192
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:187640
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for the info.
| In my case, I open both at the same time through a mainMenu in my MDI
| container.
|
| This is the code in the mainMenu:
| frm_AddNewProduct frm_myProducts = new frm_AddNewProduct(); //the parent
|
| frm_myProducts.MdiParent = this;
|
| frm_myProducts.Show();
|
| Form2 form2 = new Form2(); //Form2 inherited from frm_myProducts
|
| test.MdiParent = this;
|
| test.Show();
|
|
|
| How would I change this code (the reference part you mentioned) so I can
| manipulate any control in frm_AddNewProduct from Form2 (inherited from
| frm_AddNewProduct).
|
| Thanks again,
|
| Omar
|
| "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| news:Sr**************@cpmsftngxa06.phx.gbl...
| >
| > Hi Omar,
| >
| > I think you will show your form2 in the form1,
| > So you can pass the reference of the form1 to the form2 through the
| > constructor of the form2.
| > Then, in class form2, you got the reference of the form1, you can invoke
| > its textbox control.
| >
| > Hope this helps,
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | Reply-To: "Omar Llanos" <None>
| > | From: "Omar Llanos" <None>
| > | Subject: Filling textbox in parent form from child form
| > | Date: Thu, 25 Sep 2003 21:56:44 -0500
| > | Lines: 21
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <uq**************@TK2MSFTNGP12.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: cvx-ppp-66-50-133-170.coqui.net 66.50.133.170
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:187455
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | I have Form1 and Form2 (which is inherited from Form1), and I created
a
| > | button in Form2 that will fill up a textbox in Form1. What code would
| do
| > | that?
| > |
| > | I tried the simplest way:
| > |
| > | //from child form in button2 clicked event:
| > |
| > | textbox1.Text = "Hello";
| > |
| > | but it gave a protection level error since the parent textbox is
| private.
| > I
| > | then changed it to public but it only changes the textbox contents in
| the
| > | second form. I don't mind if it changes both textboxes , but I need to
| be
| > | able to modify the contents of the textbox in the parent form.
| > |
| > | Anyone know how to do this?
| > |
| > | Thanks in advance.
| > |
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #4

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

Similar topics

16
453
by: Adda | last post by:
If I cycle through the MdiChildActivate event of the parent form I can read text in a textbox on the child mdiform -- console.writeline(Me.ActiveMdiChild.Controls(1).Text) But if I have a sub...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.