StrataFrame Forum

Change the instance of the main BO in a form.

http://forum.strataframe.net/Topic14681.aspx

By George Nentidis - 3/6/2008

Hi all.

What I am trying to do is this: I drop a BO component (let's say CustomerBO) on the form and bind it in different controls. How can change the instance of this BO? I need to implement a method like this:

private CustomerBO mCustomer;
public void ChangeCustomer(CustomerBO newCustomer)
{
 mCustomer = newCustomer;
}

Where mCustomer is the object which is dropped on the form and bound to all controls, and newCustomer is an object created somewhere outside the form.

After the above assignment, the controls are still bound to the previous instance, and the Save method of the form still saves the original instance. Is there a way of "centrally" changing the instance of the BO (Something like the DataSource property of a BindingSource?)? Do I have to loop all controls and assign it manually?

Thanks in advance.

By Trent L. Taylor - 3/6/2008

Create a strataframe user control and drop all of your controls onto the user control.  Then drop that user control on your form and use the BOTranslations property.  This has that type of logic...there is more to  replacing an instance that just changing the property instance, all of the events, field references, etc. have to be reflectively changed in order for this to work.  This is not a SF related issue, this is just a .NET related situation where you want to change the instance of an object.  You can do this manually through the BusinessObjectTranslator class, but this is a much more complicated approach.  This is the class that is used by the User Control and ChildFormDialog when translating those business objects from one instance to another (MicroFour.StrataFrame.UI.WIndows.Forms.BusinessObjectTranslator).