Hi All,
I want to popuate a listbox with objects of different types. I display the type (humanized) of the object in the listbox.
I created a class ListBoxView that overrides the ToString method and returns a string according to the type. I create a List of ListBoxView and databind this to the listbox.
public class ListBoxView
{
private object m_value;
public ListBoxView(Object value)
{
m_value = value;
}
public override string ToString()
{
if (m_value is Car)
return "Car";
else if (m_value is User)
return "Human";
else
return "Not defined: " + m_value.GetType().ToString();
}
public T Value
{
get { return m_value; }
set { m_value = value; }
}
}
Can this better be solved with generics? Since I'm new to generics I'm having difficulties implementing using it.
Thanks
UPDATE The classes like Human and Car are part of a datamodel I can't change. I need to solve this on the user interface side