Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
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 :-
 
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 11-Jul-13 4:13am
Comments
ThePhantomUpvoter at 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?
Jayanta Chatterjee at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hello,
 
You are sending null to the second form try:
new_customer NC = new new_customer("save");//the string that you need to sent
            NC.ShowDialog();
 
on the new_customer form :
  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;
       };
    }
  Permalink  
v3
Comments
Jayanta Chatterjee at 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)

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100