Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# - Changing MDIParent propertied

Posted on 2011-03-02
5
Medium Priority
?
808 Views
Last Modified: 2013-12-17
Good afternoon,

I am writing a Windows form C# project and stuck on a simple issue where I am trying to change properties on a MDIParent from a child form and despite that there are no errors the property does not change. So here's the breakdown.

[On MDIParent1]

toolsToolStripMenuItem (Modifier - Public) (Currently set to enabled = false on load)

[On Child form]

Password box with the following code in the OK button.
 
if (txtPassword.Text == "password")
    {
     MDIParent1 parent = new MDIParent1();
     parent.toolsToolStripMenuItem.Enabled = true;
     
      MessageBox.Show("This computer has now been authorized for one session use.", "Access Granted", MessageBoxButtons.OK, MessageBoxIcon.Information);

      this.Close();
      }
      else
      {
     
       MessageBox.Show("You are not authorized to use this program", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
       }

Open in new window

I did add a break to see if it hits that code and it does but the MDIParent object remains disabled. During my step into of the break it never goes back to anywhere that re-disables the menu item. Any ideas?
0
Comment
Question by:Pandemonium1x
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1000 total points
ID: 35019043
It's because you are creating a new instance of the MDI form rather than accessing the MDI form that your current form belongs to.

Try:
MDIParent1 parent = this.MdiParent as MDIParent1;
parent.toolsToolStripMenuItem.Enabled = true;

Open in new window

0
 
LVL 4

Author Comment

by:Pandemonium1x
ID: 35019063
I did try that before actually but if I do then it breaks with a NullReferenceException (object reference not set to an instance of an object)
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35019114
Ok, that would suggest that your form isn't actually an MDI Child form. Should it be?
0
 
LVL 4

Author Comment

by:Pandemonium1x
ID: 35019142
D'oh! it appears I forgot to add my form.MDIParent = this; on load of the form. You're rank does you justice sir. Thanks, it works now!
0
 
LVL 4

Author Closing Comment

by:Pandemonium1x
ID: 35019147
Great work
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question