tags:

views:

172

answers:

3

Hi, i have a prioblem with a callback because my Form1 open Form2 and send data to Form2 after this return information to another form...please help

i can send object from form1 to form2, but the result of the form2 method must be returned by callback to another form(example form 3).

i hope that you understood my question..

A: 

When passing data between multiple forms, its often useful to store a refernceto the other forms as private variables within forms, populated only by the constructor of the form.

However, be aware that this can give you memory problems, partuicularly with events still being wired up to forms held in memory on other forms.

ck
You might also encounter locking and synchronization problems if the form methods run in different threads.
Loadmaster
+1  A: 

The fact that you have multiple forms operating on the same data means that a better option is to encapsulate that data in a set of "model" classes that can handle both handing out information to your forms and persisting any changes to storage as necessary.

The advantage of this is when you have multiple forms that need to deal with the same data, you can publish callbacks on the model objects for change notification. Each form subscribes to the events in the model that it cares about and it means any number of forms can manipulate your model and all the forms can maintain current state by reacting to notifications.

When does this way you don't care about which forms are manipulating the data and you don't need to pass anything more than the model class when launching a new form. Likewise, when a form requests a save, all the forms can update the state so they don't show the pending change.

Godeke
A: 

You could probably have your Form3 listen on the FormClosed event from Form2, then have some code to ask for the return data from Form2. Alternatively, you could create and event, FormClosedWithReturnValue(object sender, SomeArgsThatContainsReturnData data) in Form2 and have Form3 listen on that event. Hope that helps.

Jordan