Regarding NullReferenceException!!!!

  • Thread starter Thread starter Prince
  • Start date Start date
P

Prince

Hai all,

I have a statusbar control in one form but when i am assigning text
from another form it is giving NullReferenceException.How can solve
this problem??? Thanx in advance... Looking forward for the reply...

Regards,
Krish
 
Hello



Can you describe you approach more completely? Or post some code?



Did you make your status bar as a public member? Or you made you custom
property?
 
hai andrew...

this is what i want to perform in form2

statusBar1.Text = "some text " + nCount;

and status bar is in public section in form1
 
Hmmm. You should check if the statusBar1 is initialized. There is nothing
more in the code, which can produce the NullReferenceException.
 
Hi,

Post your code, NullReferenceException happen when you are trying to access
a property from an instance that is not instantiated yet, like :

trying to do like:

statusBar1.Text =" ";

before creating the instance:
statusBar1 = new StatusBar();


cheers,
 
Hi...

Actually I am having a statusbar in form1(from1.cs) and

in form2(form2.cs) i want to set text in statusbar of form1, please
give the code for setting the text of the statusbar in form2.

I did as follows in form2 :

form1 f1 = new form1();
f1.statusbar.text = "some text";

and i declared status bar as public in form1

But the text is not set... what is the reason???


Regards,
Krish
 
Prince said:
in form2(form2.cs) i want to set text in statusbar of form1, please
give the code for setting the text of the statusbar in form2.

Is form1 already visible at this point?
I did as follows in form2 :

form1 f1 = new form1();
f1.statusbar.text = "some text";

This code will create a *new* instance of form1 and set the statusbar
text on that form and *not* on your original form. To set the text of
the statusbar on your original form, you need to pass into form2 a
reference to form1, perhaps in the constructor.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top