Null reference errors are something I encounter every now and then, and normally I can detect my error and fix it.
I encounter today one that looks too simple to belive I can't fix it, but obviously I do something wrong.
Instead of wasting hours (as I already did), I ask for help.
Please look at the attached stripped-off source and help if you can.
I have a main class with a public TextBox mainDisplay,
I reference a second class.
In the second class I have a text box that referes to the mainDisplay textbox of the main class.
I am unable to display data from the second class, and I always get the text box as Null, which causes error.
See attached.
thanks
samtal
Loading
VulpesPosted Dec 16, 2011, 4:25 PM
TextBox tb = (TextBox)mf.Controls["textBox1"]; // assuming textBox1 is private and the form is its parent container
SamPosted Dec 17, 2011, 10:41 AM
Your reply gave me the direction.
I rechecked and found that I had two different initializations to the same TextBox which apparently the compiler did not detect in programming, but did not like in run time.
I removed one, and got it all right.
Thanks again. It did help.
SamPosted Dec 16, 2011, 3:51 PM
Yes, the LoadValue is the first method to be called by the Form load event.
The LoadValue has a very long list of items that all work.
I have also tried to move the LoadValues method to the form loading method (rather than its event) , but it made no difference.
I have tried every possible combination (except the right one....) but for no avail.
Is my syntax correct?
One important comment:
This is a part of a large program with tens controls, variables and fileds, serial communication and file handling, all work well for months.
I only added that display command (that apparently does not work...)
What would the right set of commands be to enable sending text from any class to the main form TextBox?
Thanks,
sam
VulpesPosted Dec 16, 2011, 1:22 PM
If you haven't then it appears that DeviceDemo.display will still be null, its default value.