Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
This is an interesting problem. I wasn't sure how to go about it, so I ended up trying several things in a little sample project. The final solution was quite easy. The key was to NOT attempt to bind the user control, but rather pass in a BO which would get bound instead.
The user control has a BusinessObject property that is of type BusinessLayer. In the setter of that property, you set the value of the bound BO for each of the controls that are bound within the user control. Since the field names are the same and the BindingField property is a string, you can just set the name in the designer for each of the bound controls in the user control. When you drop the user control on a form, you just need to set the BusinessObject property to the appropriate instance on your form. Done.
See the attached sample. It uses a "name" control. I have two BOs, both going to the same Customers table, but because BOs isolate the db from the code, it makes no difference. Two forms use the user control, each using a different BO.
Note there are the remnants from some other tries, none of which worked well (I tried using an abstract base class and then an interface, hence the name of the project).
Hope this helps!
|