I am using the following code to activate existing MDI child and refresh the grid at the same time. It was working fine until today but suddenly I am getting:\
Message=Object reference not set to an instance of an object.
at cure_hospital_management.frmMain.repositoryItemFindFile_KeyDown(Object sender, KeyEventArgs e) in C:\Users\DELL USER\Documents\Visual Studio 2010\Projects\Cure\Cure\main_form.cs:line 1718
here is the code:
foreach (Form search_resul_form inthis.MdiChildren)
frmSearchResult search_form = search_resul_form as frmSearchResult;
if ((string)search_form.Tag == "BROWSE_PATIENTS")
You will have to put in a break point and examine all the objects that may be null. Bear in mind that the error could have occurred before line 1718.
1) search_resul_form as frmSearchResult, will be null if search_resul_form is not a frmSearchResult or a derived type.
2) ((string)search_form.Tag == "BROWSE_PATIENTS" could fail for two reasons. Either search_form or Tag is null.
I have noticed the following:
if I start the application and then invoke the searcH_form then invoke any other form then call the search_form it will be activated normally without a problem
but If I start the application then call anyother form and then try to call the search_form then thsi error will occur.
Possibly something is not being initialised properly. Bear that in mind, but concentrate on determining what is causing the null reference exception as that will direct your search towards the mistake in your code. Use the debugger to find the null object and go and do it now!