MDI Access

I have an MDI application

Within my parent I have the following for storing application wide data:

public string test;

I want to be able to read and write this from within a child form but this isn't visible to the child form when I try:

this.MdiParent.test = "xxx";

Any ideas how to get this to work?

Thanks

Dave
LVL 19
daveamourAsked:
Who is Participating?
 
TheAvengerCommented:
You should cast the parent to your form type. Let's say the

public string test;

is in a class called MainForm. Then this will work:

((MainForm)this.MdiParent).test = "xxx";
0
 
daveamourAuthor Commented:
Ok that works great, would I be opening a can of worms if I asked why you had to cast?

Thanks

Dave
0
 
TheAvengerCommented:
Because the MdiParent is of type Form and you included your variable in the type MainForm. C# is stricktly prohibiting the usage of not clearly declared members/methods so you have to tell it what exactly the type is
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
daveamourAuthor Commented:
Ok I see, would have made more sense for .net to figure out what type the parent is for itself.

Thanks

Dave
0
 
TheAvengerCommented:
Not possible during design time because you can change it whenever you want....
0
 
daveamourAuthor Commented:
Good point
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.