Retrieving Information from the Parent Form of a Dialog Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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;
 
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;
 
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.
 
Back
Top