Quick question, is it possible to bind a combobox to a list of objects, but have the selectedvalue property point to the object, not a property of the object.
I only ask because we have some Business Objects which have references to other objects - such as a 'Year' object. That year object may need to be switched out for another year object.
Only solution I can come up with is to have another class with a single property, in this case pointing to a year object. then bind the combobox to a List of these and set both the display and value members to the single property.
But doing that for any 'lookups' we have seems like a bit of a pain??
Marlon
You can bind a ComboBox to any list of values using the DataSource property. Or actually:
You then use the ValueMember to control what you get from SelectedValue. Settings this to
null
as jmservera writes lets you get the object as it is in theDataSource
.If you set the ValueMember to null the selected value will always be the object, not a property: