473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

I am "Object reference not set to an instance of an object."/SubForm/MainForm/busObje

I am getting the error "Object reference not set to an instance of an object." after launching a child form by a click of a button, reason why I know of is due to setting MdiParent to Null in order to launch this new form which leads to nulling out the reference of the busObject/main form, how can I restore the busObject/main form and avoid the error?

Here is some code:

1) Here where the new/child form is being launched:
Expand|Select|Wrap|Line Numbers
  1.             Form newForm = new QueryResearchGridControl();
  2.             newForm.MdiParent = null;
  3.             newForm.TopLevel = true;
  4.             newForm.ShowDialog();
  5.             newForm.MdiParent = this;
2) Here is some code from QueryResearchGridControl():
Expand|Select|Wrap|Line Numbers
  1.   //This was a Control, now it is a form with a Control:
  2.     public partial class QueryResearchGridControl : Form   
  3. {
  4.  
  5.         public QueryResearchGridControl()
  6.         {
  7.             TopLevel = false;
  8.             InitializeComponent();
  9.  
  10.         }
  11.  
  12.         private IResearchGridBusinessObject busObject;
  13.         private BaseResearchGridForm myParent;
  14.  
  15.     public void Initialize(BaseResearchGridForm parent)   
  16.     {
  17.             myParent = parent;
  18.             busObject = parent.BusinessObject;
  19.     }

So as you probably notice that when MdiParent is being nulled out in item 1 above, it is causing the busObject to be null.
Oct 4 '10 #1
2 2007
Joseph Martell
198 Expert 128KB
You could add a ParentChanged event handler to your child form. That way you avoid the null reference exception, but your code would still execute when the parent is eventually set.
Oct 5 '10 #2
I am re writing my reply in case previouse one did not post.

Hello Joseph,

Thank you for the feedback, I found out that mdiPrent has nothing to do with what I was doing so I removed it from my code, after further research I found out that I need to instantiate the busObject, allow me to explain, when the main form is launched (BaseResearchGridForm), a button is clicked to launch another form that hosts a control (newForm/QueryResearchGridControl), all is working well so far, but once I click the "Search" button on the new form (newForm/QueryResearchGridControl) I get the error (null reference....) at the busObject assignments...etc. I need to instantiate the busObject but I am new in c#/OO in general so I wonder if you can make some further recommendations. Thanks in advance.
Oct 6 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bob Cannistraci | last post by:
A three-tier user authentication system was running without a problem for almost a year and now is suddenly dysfunctional. We don't know of any changes to any of the servers. It's quite maddening....
1
by: vijay | last post by:
Hi I am working on a web application. I have huge form where in I have filled some part of the form and after two hours again I started filling the rest of the form but I got the following error ...
1
by: Chris Magoun | last post by:
I suddenly received an unexpected error in my project. I have been working on this project for some time without this issue. Nothing has changed in the form that caused the exception. A little...
18
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12,...
9
by: MrSpock | last post by:
1. Create a new Windows Application project. 2. Open the project properties and check "Make single instance application". 3. Build. 4. Go to the release folder and run the application. 5. Try to...
1
by: DaveO. | last post by:
Hello, I'm calling a VB.NET web service, also from VB.NET, and I get the error " Object reference not set to an instance of an object" on the following line in Reference.vb, when it tries to...
2
by: louie.hutzel | last post by:
This JUST started happening, I don't remember changing any code: When I click the submit button on my form, stuff is supposed to happen (which it does correctly) and a result message is posted back...
0
by: =?Utf-8?B?SkhhbGV5?= | last post by:
Our system is: IIS Server: dual Intel Xeon 2.80 GHz, 4 GB Ram Windows Server 2003 SP2 IIS 6.0 SQL Server: dual Intel Xeon 2.80 GHz, 4 GB Ram (separate server) Windows Server 2003 SP2 SQL...
0
by: Tamer Ibrahim | last post by:
Hi, Sometimes, I got the following error message when I use ajax calendar control on some aspx pages : Object reference not set to an instance of an object. Description: An unhandled exception...
2
by: Monty | last post by:
I'm installing an ASP.Net 2.0 web applications project (WAP) application on a production server (Win 2003). I've installed it on XP test machines before and it runs fine. On my production machine I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.