473,395 Members | 1,666 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,395 software developers and data experts.

Updating a variable in a Parent Form from a dialog box.

Hi All,

Just wanted to know how to update a public variable in a parent form from a
dialog box. It appears that i get a null reference error when assigning the
variable as follows:

((FormMain)this.ParentForm).loggedIn = true;

Can anybody shed some light?

Thanks,
Jesse
Nov 15 '05 #1
4 5950
I'm not sure, but i think that if is not a modal form, it has (as default)
no parent.

But you can always set it when you istantiate it

Form myChildForm=new Form();
myChildForm.Parent=this;

"Jesse" <je*****@hotmail.com> schrieb im Newsbeitrag
news:eW**************@TK2MSFTNGP12.phx.gbl...
Hi All,

Just wanted to know how to update a public variable in a parent form from a dialog box. It appears that i get a null reference error when assigning the variable as follows:

((FormMain)this.ParentForm).loggedIn = true;

Can anybody shed some light?

Thanks,
Jesse

Nov 15 '05 #2
Hi,

I would do another thing, I will pass a reference to the parent to the
constructor of the dialog:

Form childform = new ChildForm( this );
childform.ShowDialog();

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:On**************@TK2MSFTNGP10.phx.gbl...
I'm not sure, but i think that if is not a modal form, it has (as default)
no parent.

But you can always set it when you istantiate it

Form myChildForm=new Form();
myChildForm.Parent=this;

"Jesse" <je*****@hotmail.com> schrieb im Newsbeitrag
news:eW**************@TK2MSFTNGP12.phx.gbl...
Hi All,

Just wanted to know how to update a public variable in a parent form
from a
dialog box. It appears that i get a null reference error when assigning

the
variable as follows:

((FormMain)this.ParentForm).loggedIn = true;

Can anybody shed some light?

Thanks,
Jesse


Nov 15 '05 #3
ParentForm is really a property to get the form that your control is sited
on, (which is very handy for MDI forms). Try using "Parent" instead:

In your calling form (FormMain):

ChildForm cf = new ChildForm();
cf.Parent = this;
cf.Show();
Then in your child form:

((FormMain)this.Parent).loggedIn = true;

"Jesse" <je*****@hotmail.com> wrote in message
news:eW**************@TK2MSFTNGP12.phx.gbl...
Hi All,

Just wanted to know how to update a public variable in a parent form from a dialog box. It appears that i get a null reference error when assigning the variable as follows:

((FormMain)this.ParentForm).loggedIn = true;

Can anybody shed some light?

Thanks,
Jesse

Nov 15 '05 #4
Thanks for the help. All very good suggestions.
"Jesse" <je*****@hotmail.com> wrote in message
news:eW**************@TK2MSFTNGP12.phx.gbl...
Hi All,

Just wanted to know how to update a public variable in a parent form from a dialog box. It appears that i get a null reference error when assigning the variable as follows:

((FormMain)this.ParentForm).loggedIn = true;

Can anybody shed some light?

Thanks,
Jesse

Nov 15 '05 #5

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

Similar topics

2
by: Dennis C. Drumm | last post by:
I have a window form dialog that I use in a non modal fashion. It is displayed using Show() in stead of ShowDialog() from the parent windows form application. I have TextBoxes in that dialog that...
1
by: lewi | last post by:
How do I access data members of a parent form class and from a function of a child form class. Both classes are both in the same name space and are public classes... The child form is a Modal...
4
by: kids_pro | last post by:
Hi there, I want to create a Modal dialog from. Normally in vb it won't allow to click the parent form. But I tried that in C# using form.ShowDialog(this); I still can click on the mainForm...
2
by: Paul | last post by:
Hi this is related to a previous post, hopefully just a bit clearer description o the problem. I have a parent form that opens a new form (child form) while still leaving the parent form open....
3
by: LEE | last post by:
I'd like to call a function of child from parent form, there is an issue: Form1 (parent) calls "LoadMe" Sub in Form2 (child), it works using the codes (in Form1): Dim frm As New Form3()...
1
by: Agnes | last post by:
my Parent will call a child form by click a button myChild.showdialog() Now, As I mininumized the Parent form, How can I minized the Child Form also ?? Thanks a lot
3
by: cbrown | last post by:
I have two forms Main & Child. Main has several readonly properties that I would like to access from the child form. How do I reference the MDI-Parent form MAIN and use those properties.
9
by: cybervegan | last post by:
Hi, First, the background info: I have a parent form, New_Jobcard that contains a combo-box to select Cust_ID. The combobox shows customers sorted by name and address, like this: Cust_ID V ...
0
by: ppotter10 | last post by:
I'm working on an app which uses a parent form and child forms in C++.Net. I want to access a static arraylist variable of the parent form from a child form. In order to do so, I wanted to use the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.