Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to call a form to another form, but I want the calling form shows like dialog box(not resizing). I passing parameter to my new_customer form's constructor.
so My code is :-
new_customer NC = new new_customer(null);
            NC.ShowDialog();


My new_customer form constructor :-

C#
public new_customer(string formType="save")
       {
           InitializeComponent();
           DC = new Data_Conn(Application.StartupPath);
           DC1 = new Data_Conn(Application.StartupPath);
           paraModi = formType;
       }

Problem is when I call new_customer form from another form, its constructor doesn't execute,that's why I get an error when I use that variable :
Object reference not set to an instance of an object.


thanks In advanced ..
Posted
Comments
[no name] 11-Jul-13 9:42am    
How is it that you know that your constructor is not called? Did you run your code in the debugger? What line of code is giving you the "Object reference not set to an instance of an object" error? Are you getting any other exceptions that is causing your form constructor to fail?
JayantaChatterjee 11-Jul-13 9:52am    
thanks for quick reply..
I passing null value to my parameter that's why I'm getting error(as said @jokler.007)....

1 solution

hello,

You are sending null to the second form try:
C#
new_customer NC = new new_customer("save");//the string that you need to sent
            NC.ShowDialog();


on the new_customer form :
C#
  public partial class new_customer: Form
    {
string formType;

public new_customer(string formType)//formType=save that you have sent
       {
           this.formType=formType;
           InitializeComponent();
           DC = new Data_Conn(Application.StartupPath);
           DC1 = new Data_Conn(Application.StartupPath);
           paraModi = formType;
       };
    }
 
Share this answer
 
v3
Comments
JayantaChatterjee 11-Jul-13 9:50am    
Thanks a lottttt..
Its workssssssss..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900