Hello,
With the .NET ComboBox, I can bind a generic List of our objects (e.g. List<Customer>) as its datasource (not setting DisplayMember / ValueMember) and the text displayed for each object is its overriden ToString() method.
With the UltraComboEditor, I bind the same list of objects (still not setting DisplayMember / ValueMember), but the text that is displayed for each object is its class name.
Is there a built-in way I can get the UltraComboEditor to behave like the .NET ComboBox and display each object using its ToString() method?
If not, is there a way I can inherit from the UltraComboEditor and take advantage of an override to display each bound object using its ToString() method?
Thanks,David McClelland
OK, so I dug through the UltraComboEditor's source code that we have, and it turns out that specifying the DisplayMember and ValueMember as:
Infragistics.Win.BindableValueList.USE_LISTOBJECT_AS_VALUEMEMBER
... does the trick! This is noted in the documentation for the UltraComboEditor's ValueMember property, but not in the documentation for the DisplayMember property.
I'm so glad I found this - I do hope in the future this behavior can be made a property of the UltraComboEditor so that it's more visible to developers.
- David McClelland
Hi David,
You should not have to set USE_LISTOBJECT_AS_VALUEMEMBER. I ran your sample and it works fine for me. So you must be using an old version and what you are seeing is a bug. How to get the latest service release - Infragistics Community
USE_LISTOBJECT_AS_VALUEMEMBER
A colleague just pointed out to me that I appear to have misunderstood your question here.
The UltraComboEditor is supposed to behave differently than the MS ComboBox. The ComboBox control basically uses the data object in each row of data as the value for the combo. So the items in the combo in your sample are the actual items of data in your List. Each row is a customer object and so it displays the ToString of each object and if you pick an item from the list, the combo's Value returns that Customer.
UltraComboEditor is intended to allow you to choose a particular field from the customer, rather than the Customer object itself. So in this case, since you did not specify a ValueMember, it just uses the first field it finds, which happens to be the last name. The list displays the same thing, since you also did not set a DisplayMember.
The reason for this is that it allows you to do some really cool stuff like displaying one field to the user on a list and then saving an ID as the UltraComboEditor's Value.
Anyway... your solution is the correct one. We added that constant specifically to allow you to do display or save the actual object instead of just a single field.
Sorry for the confusion, and there is no need for you to update to the latest service release. :)
I am using the 2009 vol 1 version (without any service release applied). I will see if our team can upgrade to a service release. Thanks for the heads-up!