Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i was asked to save something from a different window. from it's own window it works fine. but when i do this :

C#
ActivityEditorView aev = new ActivityEditorView();
aev.LoadActivitynoeq(sender, e);


everything is saved as null. i think because i am creating a new instance of the form. any ideas please?
Posted
Updated 17-Aug-11 3:46am
v3
Comments
Herman<T>.Instance 17-Aug-11 9:20am    
what's the code in LoadActivitynoeq()?
Anthony Mushrow 17-Aug-11 9:30am    
It seems you'll need to have access to the existing instance of the form, instead of using a new one. How you get hold of the instance entirely depends on how your application is set up, so I can't really help there.

The whole question seems wrong to me. Surely what you've been asked to do is save the contents of a different piece of the data model – not 'another window'. (Saving a view doesn't really make sense.) If that is the case then the two parts of the model should be linked (otherwise it is a silly requirement and you should tell the person that gave it to you so), and therefore this view can look through its own reference to a model object, through the link and find the model object which it should call a Save method on. If the link doesn't exist in code, but you think it is a reasonable thing to request, then you need to add a link in the model (or view model; see below) – and if that seems unnatural, have a think about whether the requirement actually makes sense.

Depending on what exactly the problem is, this link might be at the model-view level, not the model-level. I can't answer which of those is better based on such a vague question. But the link should not be at the view level.
 
Share this answer
 
You have to be able to get a reference to the form (if it's open). That means that your current form either has to be passed the form reference, or somehow gain access to it. At that point, you have to be able to access the property in that form that you need.

Creating a new instance of the form is not the correct approach, and how you provide a refence to the current form is completely up to you.
 
Share this answer
 
Hi
Why don't you use delegate and event handler ?

if I see your code, I can help better.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900