I am using the VS2010 C# language.
I have a form with ENTER button which create an object of class ORDER in Enter_Click(..) event. Now I have another button ADD ITEM which suppose to add a new item in an order when it is clicked.
I tried to access an Order object created in ENTER button click event, in ADDITEM_Click(..) event, I got the following error:
“Object does not exist in current context”
Any help will be greatly appreciated.
The scope of your Order is limited to the
Enter_Click()event because that is where you declare it. Add the lineOrder myOrderat the class level and it will work because the object will continue to exist after theEnter_Click()method finishes.