Hi, I'm new to CSLA (using CSLA 2 for VB)
I have Product object which one of the field is ComboBox referring to SupplierList object. When I create a new Product, initially Supplier's ComboBox is showing 'key' instead of 'value' (I can see 'value' when I clicked ComboBox). If I tried to choose a Supplier, an exception occured 'Input string was not in a correct format'.
I have tried to use SupplierList object in a form (no object binding) and it worked perfectly.
Can anyone please enlight me, what I have missed ? Thank you.
Anyone can help me
Here's what I've done :
- create SupplierList (inherit from NameValueListBase)
- in Product's form constructor
Public Sub New(ByVal product As Product)
InitializeComponent()
mProduct = product
mProduct .BeginEdit()
Me.SupplierListBindingSource.DataSource = SupplierList.GetList
Me.ProductBindingSource.DataSource = mProduct
ApplyAuthorizationRules()
End Sub
- in Product's form design, at Dealer's combobox, I set DataSource to SupplierListBindingSource, DisplayMember to Value, ValueMember to Key
Is there anything I missed ? Thank you.
You probably also have a databinding on combo.Text that makes the combo show the Key initially.
Forms designer automatically adds a databinding to .Text when you add a ComboBox from the datasources window.
Hi Jonny,
Thanks for replying.
The ComboBox has binding to SupplierId of Product object. The ComboBox .Text property is binding to SupplierId, but has no value.
Could you please elaborate more ?
The Combobox doesn't have a DataMember property - instead it has a DisplayMember and ValueMember property:
- The DisplayMember of a Combobox gets or sets a string that specifies the property of the data source whose contents you want to display.
- The ValueMember property determines which value gets moved into the SelectedValue of the Combo Box. In the example, whenever the user selects a Customer by "Customers.CompanyName", the SelectedValue is the "Customers.CustomerID". Whenever the SelectedValue changes, the data-binding moves the new value into the Customer object.
So you would typically setup databinding only on:
You would only want to setup databinding on combo.Text if you use the styles Simple or DropDown where the combox acts like a text box with a list of "suggested" selctions but still allow the user to enter a new text value. (And in in this case the SelctedValue will have no meaning when you add new items/string values).
Thanks a lot Jonny
I thought Text property in the DataBinding as Text property. Now everything worked like a charm.
Copyright (c) Marimer LLC