New Posts New Posts RSS Feed: User Controls
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

User Controls

 Post Reply Post Reply
Author
m2r4miller View Drop Down
Newbie
Newbie
Avatar

Joined: 19-Aug-2007
Location: United States
Posts: 12
Post Options Post Options   Quote m2r4miller Quote  Post ReplyReply Direct Link To This Post Topic: User Controls
    Posted: 19-Aug-2007 at 7:09pm

Is it possible to develop a user control that manages, say a Contact Business Object and then use that control on a form and at runtime automatically bind the control to the appropriate Contact Business Object?

Consider this data layout:

(1) Supplier Business Object with Name, Start Date (etc) and Contact properties.

(2) Vendor Business Object with Name, Start Date, Credit Limit (etc) and Contact properties
 
(3) Contact Business Object with Phone, Fax, Email properties, all backed by the Contact table.
 
In both Supplier and Vendor, Contact is a Foreign Key relationship to the Contact Business Object
 
The Contact BO holds the contact information for Supplier and Vendor.

My goal is to create a User Control that manages the Contact BO, and be able to drop it on either the Supplier or Vendor maintenance forms and wire it so that it would work the same as if I had built the form using the ControlBindingManager and dropped the nested Contact properties onto the form.

It seems to me this should be possible, has anyone done this?
Can someone provide some examples?
 
I have studied the tutorial "Composing Forms with User Controls", which is helpful, but does not deal with the situation I describe.
 
Any help/ideas would be most helpful.
 
TIA,
 
Mark
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 20-Aug-2007 at 10:18am
In "Composing Forms with User Controls", the OrdersUserControl is used on both the Employee and Customer TabPages, displaying Order data appropriate to the context. The relations Employee->Order and Customer->Order are 1-to-many, but otherwise this situation is similar to your Contact scenario.  You should certainly be able to create a ContactUserControl with a LoadData() method that takes an EntityList of Contacts -- which can be an EntityList with one member.
 
(Partial) Code in ContactUserControl:
------------------------------------------------
 
EntityList<Contact> mContacts = new EntityList<Contact>();
 
void ConfigureBindingSources() {
mContactsBindingSource.DataSource = mContacts;
}
 
void ConfigureBindingManagers() {
mContactsCBM.BindingSource = mContactsBndingSource;
}
 
void LoadData(EntityList<Contact> pContacts) {
mContacts.ReplaceRange(pContacts);
}
 
All of your control bindings would be represented (as usual) as ControlBindingDescriptors in the ControlBindingManager's Descriptors collection.
 
Greg Dunn
IdeaBlade
 
Back to Top
m2r4miller View Drop Down
Newbie
Newbie
Avatar

Joined: 19-Aug-2007
Location: United States
Posts: 12
Post Options Post Options   Quote m2r4miller Quote  Post ReplyReply Direct Link To This Post Posted: 23-Aug-2007 at 6:51am
Thanks Greg - I missed that in the tutorial. I will have the chance to look it over tomorrow (Friday) and if I can't figure it out I'll be posting here.
 
Thanks again!
-Mark
Back to Top
m2r4miller View Drop Down
Newbie
Newbie
Avatar

Joined: 19-Aug-2007
Location: United States
Posts: 12
Post Options Post Options   Quote m2r4miller Quote  Post ReplyReply Direct Link To This Post Posted: 09-Sep-2007 at 11:01pm
Greg,
 
After a little trial and error I was successful in building a Address user control that I can add to a form and have it synched properly to the parent Business Object.
 
In the Binding Navigator MoveFirst, MoveNext, etc button click events, I call a LoadCurrentAddress() method that simply calls my Address user control LoadMainData(int? id) method, passing in the AddressID value from the BindingSource.Current reference.
 
Works like a charm!
 
Now I will implement the necessary CRUD methods in the Address User Control and wire that to the main form as well and then I should be where I want to be with this control.
 
Thanks again for your help!
-Mark


Edited by m2r4miller - 09-Sep-2007 at 11:16pm
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 10-Sep-2007 at 11:18am
Quite welcome, Mark.
 
>>
In the Binding Navigator MoveFirst, MoveNext, etc button click events, I call a LoadCurrentAddress() method
<<
 
Rather than put separate calls in MoveFirst, MoveNext, etc., can you just put one in the BindingSource.CurrentChanged event handler?
Back to Top
m2r4miller View Drop Down
Newbie
Newbie
Avatar

Joined: 19-Aug-2007
Location: United States
Posts: 12
Post Options Post Options   Quote m2r4miller Quote  Post ReplyReply Direct Link To This Post Posted: 10-Sep-2007 at 11:43am

You are quite right - I didn't think of that (of course it was after 1 am Sleepy)!

The event handler works perfectly and of course is the way to go.
 
Thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down