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:\
System.NullReferenceException occurred Message=Object reference not set to an instance of an object. Source=Cure StackTrace: 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 InnerException:
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.
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!