How can I access another form's BO in a form?


Author
Message
Ben Hayat
Ben Hayat
Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
I must be missing something that I can't see or reference a form or variable from another form's BO.



In my Main form, I have a BO that acts as the parent to several other BOs that are in other forms. My question is in two fold:

a) In the employee form, when I drop a BO, how can I tell it in designer that the "ParentBusinessObject" is the one in Main Form?

b) By the same token, in this employee form, how do I access the BO in the Main form and other public variables I had set.



Somehow I'm need to tell Employee form to reference to Main form.



I think Randy had the same problem, and I had given him a solution that doesn't even work for myself.



Thanks!

..ßen
Replies
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Well, I'd still look into Shared Datatables or into BO translations.



Have you thought of maybe making a static (shared in VB) class with a property to hold this BO? I.e. rather than dropping the BO on the main form, configure this static class with the BO. Then you could set that BO in any form you wanted using the BusinessObjects.Add() method of the form.



E.g.

// Static class that holds the instance of the BO that will be used.

public static class MasterBOAccessor

{

private static MyMasterBO _businessObject;

public static property MyMasterBO BusinessObject()

{

get

{

return _businessObject;

}

set(MyMasterBO value)

{

_businessObject = value;

}

}

}



// Main form class that reference the main BO

public class MyMainForm : Microfour.StrataFrame.UI.Windows.Forms.StandardForm

{

private sub form_load(object sender, EventArgs e)

{

this.BusinessObjects.Add(MasterBOAccessor.BusinessObject);

}

}



// Child form that will use the main bo as the parent of a BO loaded onto

// this form (myChildBO)

public class MyChildForm : Microfour.StrataFrame.UI.Windows.Forms.StandardForm

{

private sub form_load(object sender, EventArgs e)

{

this.myChildBO.ParentBusinessObject = MasterBOAccessor.BusinessObject;

}

}




NOTE: I don't know that this will work, but I think it should. Also, if you see things in this code that looks wrong...well it probably is, I don't know C# that well Tongue



Ben Hayat
Ben Hayat
Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Greg; Thank you very much for your time and effort;



I'll be getting up 5:00 AM tomorrow morning to drive to Orlando for TechEd07. After I get back, I'll look into this as well. Perhaps SF Team will also add in some suggestions.



I think to summarize my point, is that, I need one BO (StoreBO) that should be set in the mainForm, with proper filter. Then In Employee, customer, tax, Order, etc. forms, all those BOs should use that StoreBO as their parentBusinessObject.



I tried it today, but when I set the EmployeeBO.ParentBusinessObject in Employee FormLOad Event, I then get error that the Employee.ParentBO is Null.



That's the idea!

..ßen
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
By my guess, it looks like the main form is going to be creating and showing the instances of the other forms.  There isn't a way within the designer to tell a component on one form to reference a component on another form (the form designer does not know that the other form exists.  So, you will have to set the parent programmatically.  Your best bet would be to add a parameter to your child forms' constructors that accepts the parent business object; then set the ParentBusinessObject property on the child BOs after the InitializeComponent has been called.  Then, all you need to do is pass over the parent business object when you create new instances of the child forms.
Ben Hayat
Ben Hayat
Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Ben Chase (06/06/2007)
By my guess, it looks like the main form is going to be creating and showing the instances of the other forms. There isn't a way within the designer to tell a component on one form to reference a component on another form (the form designer does not know that the other form exists. So, you will have to set the parent programmatically. Your best bet would be to add a parameter to your child forms' constructors that accepts the parent business object; then set the ParentBusinessObjectproperty on the child BOs after the InitializeComponent has been called. Then, all you need to do is pass over the parent business object when you create new instances of the child forms.




Ben, I'll look into this further probably this weekend and if I have more questions, I'll ask next week. But you gave me a good starting point!

Thanks!

..ßen
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Ben Hayat - 18 Years Ago
Ben Hayat - 18 Years Ago
Greg McGuffey - 18 Years Ago
Ben Hayat - 18 Years Ago
Greg McGuffey - 18 Years Ago
                         Greg; Thank you very much for your time and effort;

I'll be...
Ben Hayat - 18 Years Ago
                             By my guess, it looks like the main form is going to be creating and...
StrataFrame Team - 18 Years Ago
                                 [quote][b]Ben Chase (06/06/2007)[/b][hr]By my guess, it looks like the...
Ben Hayat - 18 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search