Hi , friends
I am facing a problem in windows application in C#.net 2.0
scenario is , i hav a public int variable in a form's class , and from that i am opening a dialog form and from that dialog form i am assigning value to that variable but , at run time i get an error "Object is not set to an insatance of an object "
please tell me where i am wrong
waiting for reply ....................................................................
Loading
Siddhartha SarkarPosted Oct 10, 2008, 5:12 AM
Hey Dheeraj,
Without the code that you are using it is difficult to suggest a solution. However, I would like to mention the following things:
1) Use of a class property is always preferrable over use of public variables. And also a better programming practice.
2) From the second form that you are opening from the first form how are you accessing the first form's variable. Mind this.
Can suggest you a solution but only after a more detailed picture of the scenario.
Regards,
AlanPosted Oct 10, 2008, 5:08 AM
How are you getting a reference to the form from the dialog?
If MyForm is the name of the form containing the int variable (MyInt let's say) then try the following code from the dialog:
MyForm mf = (MyForm)this.Owner;
mf.MyInt = 42; // or whatever
This should work as long as MyForm is the owner of the dialog which is the default position.