Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Retrieving Information from the Parent Form of a Dialog Box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Betty - 01 Feb 2005 16:31 GMT
I'm trying to access public properties of the parent form of a dialog form,
using the example within Visual studio, i still can't get it to work. I keep
getting an error that

*** Object reference not set to an instance of an object *****

what am I missing?
Thanks in advance

the following  code is located on a button of the parentform
********
           FSGMaint fsdgm = new FSGMaint (  );
           fsdgm.ShowDialog(this);
ProductDesc is a public property of FSDSetup which is the parent form

______________________________________
within the opened form *FSGMaint* is the following code
__________________________________
 string x = ((FSDSetup)this.ParentForm).ProductDesc;
saurabh - 01 Feb 2005 17:30 GMT
First check whether ParentForm is null or the casting is wrong.

> I'm trying to access public properties of the parent form of a dialog
> form,
[quoted text clipped - 17 lines]
> __________________________________
>  string x = ((FSDSetup)this.ParentForm).ProductDesc;
Morten Wennevik - 01 Feb 2005 17:44 GMT
Hi Betty,

ParentForm is used for when a Control is contained within another  
control.  This is true if the Parent Form is an MdiContainer and you set  
the Child control's MdiParent property to point to this parent.

Try something like this instead:

FSGMaint fsdgm = new FSGMaint (this);
fsdgm.ShowDialog();

And in the constructor of FSGMaint:

private FSDSetup myParent;

public FSGMaint(FSDSetup parent)
{
    myParent = parent;
}

Then in the click event:

string x = myParent.ProductDesc;

====================================
Or using MdiParent:

this.IsMdiContainer = true;
FSGMaint fsdgm = new FSGMaint();
fsdgm.MdiParent = this;
fsdgm.Show();

...

string x = ((FSDSetup)this.ParentForm).ProductDesc;

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Betty - 01 Feb 2005 19:29 GMT
Hi Morten,
This worked....thank you!

> Hi Betty,
>
[quoted text clipped - 31 lines]
>
> string x = ((FSDSetup)this.ParentForm).ProductDesc;
GrkEngineer - 19 Apr 2005 02:13 GMT
I'm having this same problem in C++/CLI and I understand everything you
listed, but I'm running into a problem. When I try to cast using

> string x = ((FSDSetup)this.ParentForm).ProductDesc;

I get an error because my compiler doesn't know what FSDSetup is. If I add
the header file FSDSetup.h to the FSGMaint.h, I get an error because I've
already added it to the main form and I've now created each file referencing
each other. Please help me.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.