Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

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
0
daveamour
Asked:
daveamour
  • 3
  • 3
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now