Hi,

I have a list of objects of type T which I am adding to a combobox via
the myComboBox.Items.Add() method.

My question is, is there any way to control the display name without
trying to subclass or wrap T? T does not publish any properties, and
is an object from an external library so I cannot make it (can I?),
despite knowing exactly how I would like to make it display.

So at the moment I'm thinking the approach is to wrap T like so:

class U
{
        T value;
        public String Text
        {
                get {
                        // call value.foo(), value.bar(), return the formatted 
string I
want
                }
        }

        public T Value
        {
                get { return value; }
        }
}

and then

T t = ...;
myComboBox.Items.Add(new U() { value = o });
myComboBox.DisplayMember = "Text";
myComboBox.ValueMember = "Value";



So I guess this works (I have not tried this yet) but it seems
somewhat heavy handed. Is there not an easier way to do this? I was
thinking surely it would be easier if ComboBox (or more to the point
ListControl) simply allowed you to specify lambdas to transform the
text, this would be much more straightforward? That way you could use
t => t.MyProperty or t => { /* t.foo(), t.bar() etc */ } as necessary?

Reply via email to