Bineesh Viswanath

Bineesh Viswanath

  • 1.3k
  • 424
  • 43.3k

Form not closing in Form.Close() function

Sep 12 2019 7:56 AM
Dear All,
 
I need your help to solve below issue:-
 
I have an issue when I am trying to close a windows form by calling form.close() function.
 
The scenario is mentioned below:-
 
I am using a mdi form. From menu I opened a child form. Then from child form(child), I opened another form(non -child)outside the container. in non child form I am using a database insert function. After insert, I am closing the non child form and I need to re open the child form in order to reflect the data saved from non child form.
 
in non child form , I wrote like this:-
 
frmMain mainObj = new frmMain();
Close();
mainObj.OpenAssetViewForm();
 
And in Main form , i wrote like this to open child form within container.
  1. public void OpenAssetViewForm()  
  2. {  
  3. try  
  4. {  
  5. foreach (Form frmObj in Application.OpenForms)  
  6. {  
  7. if (frmObj.Name == "frmAssetRegView")  
  8. {  
  9. frmObj.Close();  
  10. if (frmObj == null)// is not changing into null  
  11. {  
  12. frmObj.Show();  
  13. }  
  14. break;  
  15. }  
  16. }  
  17. }  
  18. catch (Exception ex)  
  19. {  
  20. }  
  21. }  

Answers (8)