konrad konrad - 1 year ago 47
C# Question

populate combo box from BindingList<Wrapper> and return the Wrapper itself

Is it possible to do this:

public class ParameterWrapper
public string Name { get; set; }
public Definition Definition { get; set; }
public StorageType StorageType { get; set; }

and then use it in a
to bind it to a ComboBox control like this:

private void PopulateDropdownBinding(ComboBox control, BindingList<ParameterWrapper> parameters)
control.DataSource = parameters;
control.DisplayMember = "Name";
control.ValueMember = ???;

Where I have the "???" is my question. I want to return the actual Wrapper object. So the Display Name is the Wrapper.Name but Display Value is Wrapper. Can that be done?

Of course I could take the
and stick into a
Dictionary<string, ParameterWrapper>
but I was hoping for a more streamlined solution. Ideas?

Answer Source

If you leave ValueMember unspecified, Value will return the item itself -- in this case, your ParameterWrapper instance.

Much less here than meets the eye!