Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return a new object by reference 1

Status
Not open for further replies.

markftwain

Technical User
Jul 12, 2006
108
Hi experts,

Newbie question: How do I return a new object from a child window back to the calling window? (The child window is to perform edits on the object but only keep those edits if user presses <save>, othewise, no editing is to be kept). I am sure this is done often.

I am using C# with .Net 4.0 and visual studio 2010 on windows 7.

My first window creates an object as:
myclass o1= new myclass();

Then calls window_2 as:
window2 w2= new window2( ref o1);

in the initialization code for window2, I have:
p1 = o1;
where p1 in the window2 class defintion was declared as:
public myclass p1;

Window2 now creates a new object n1 based on the information obtained from p1/o1 and allows the user to edit the new object n1 (of same class). When the user presses <save> in window2, I am trying to pass the new object n1 (created in window2) back to the calling routine of window 1, so in the save_click of window2, I put:
p1=n1;

When window2 is now unloaded, window1 is NOT receiving the newly created object n1, but rather still has the original o1.

How is this done correctly?

Any help is very much appreciated. Thank you.

 
I don't know the scope of o1.
What I would do will be to create a property MyClass in window2 (type myclass) then the code will be like :

myclass o1= new myclass();
window2 w2= new window2();
w2.MyClass = o1;
if (w2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
o1= w2.MyClass;
}
w2.Dispose()


Viewer, scheduler and manager for Crystal reports.
Send your report everywhere.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top