New Posts New Posts RSS Feed: Combobox binding
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Combobox binding

 Post Reply Post Reply
Author
jcdk View Drop Down
Newbie
Newbie


Joined: 25-Aug-2007
Location: Denmark
Posts: 11
Post Options Post Options   Quote jcdk Quote  Post ReplyReply Direct Link To This Post Topic: Combobox binding
    Posted: 25-Aug-2007 at 10:23am
Hi
 
I am a newbie to DevForce, but I can already see that it will speed op development dramatically.
 
I do have a problem with comboboxes though. I am showing orders on a master detail form. The order has one customer. The customer has many Contact Persons. I want to display a dropdown box of Contact Persons on the form.
 
I have managed to get a list of valid Contact Persons for each order by extending the order class with ContactPersons using something like this
 
Public ReadOnly Property ContactPersons() As EntityList(Of ContactPerson)
  Get
    Dim aContactPersons As EntityList(Of ContactPerson)
    aContactPersons = Me.PersistenceManager.GetChildren(Of 
       ContactPerson)(Me.Customer,
       EntityRelations.Customer_ContactPerson, True)
Return aContactPersons
End Get
End Property
 
I would have expected that I could use this property directly in the ControlBindingManager, but I get the message "There are no controls suitable for ContactPersons".
 
I've tried to create a new datasource, chaining it after the Orders datasource, and selecting ContactPersons. Using this as a binding source for my combobox it updates the valid values correctly on each order.
 
I've then used the databinding of the combobox to connect it back to the original orders datasorce. It works when I first enter the form, but when I move back and forth the combobox stops moving.
 
I am afraid that I am on a wrong track. If I am, please show me the way.
 
Any help greatly appriciated.
 
Regards
Jesper Carstensen
Back to Top
pkarsh View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 32
Post Options Post Options   Quote pkarsh Quote  Post ReplyReply Direct Link To This Post Posted: 29-Aug-2007 at 1:00pm
You are most of the way there.

Assuming that you have defined a relation between ContactPerson and Order, where ContactPerson is the parent object, then in the ControlBindingManager you should see a "ContactPerson" property. If you drag that property onto the Autopopulation pane it should specify a ComboBox as the best fit control for that property. The DataConverter for that property should be specified as a ListConverter. You then have to configure the ListConverter.

To do that, click on the rightmost button on that row, next to the DataConverter column. A "ListConverter properties" property sheet should appear. If you do not already have a BindingSource to populate a ComboBox of ContactPersons on your form (as I would assume that you do not), click the "Create List" button at the bottom of this property sheet. A dialog box will appear to allow you to enter the name of a new BindingSource that will be created and added to the form. Fill in something on this form, then select the DisplayMember of the ContactName that you want to have appear in the ComboBox. I will assume for the purposes of this explanation that this class has a property called "LastName". Select that property so that the last name of the ContactPersons will appear in the ComboBox. Click OK, etc. to exit the property sheet.

Now what you want to do is populate the BindingSource you just created above with the ContactPersons that would be valid for the selected Order. One way to do this is to implement an EventHandler for the CurrentItemChanged event for the BindingSource that is populating the Order ControlBindingManager. Within this EventHandler, add code that looks something like:

Order aOrder = (Order)OrderBindingSource.Current

I apologize for the C# code. Basically you will have to cast the OrderBindingSource.Current object to an Order object and I'm a little shaky on the use of the CType cmmand in VB.

You would then have a line of code that reads something like ContactPersonsBindingSource.DataSource = aOrder.ContactPersons

where you reference the property you defined in your Order class.

Now what should happen is that for any particular Order that is displayed the list of possible ContactPersons that is appropriate for the Customer who placed the Order should appear. The current setting in the ComboBox would be the actual ContactPerson that is currently set for that Order. If you change the selection in the ComboBox, then, with DevForce's bidirectional data binding, when you Save the change, the new ContactPersonId should be set in the database for that Order.

Obviously I have made some assumptions about variable names, etc. I hope my explanation is clear nonetheless.
Back to Top
jcdk View Drop Down
Newbie
Newbie


Joined: 25-Aug-2007
Location: Denmark
Posts: 11
Post Options Post Options   Quote jcdk Quote  Post ReplyReply Direct Link To This Post Posted: 02-Sep-2007 at 11:54am
Thanks a lot for your help.... I've got it now.
 
I am impressed by the level of support you deliver at IdeaBlade. That tells me that the decision to use DevForce for our development project is correct.
 
Thanks again   Thumbs%20Up
Jesper Carstensen
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down