How do other people get around having to define the ValueMember in a
DataGridViewComboBoxColumn when binding to a list of business objects?
I'm currently doing the following, and it feels wrong and woefully
misguided.
public class SomeClass
{
private string name;
public SomeClass(string name)
{
this.name = name;
}
public string Name
{
get{return name;}
}
public object This
{
get{return this;}
}
}
so that I can specify:
DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn();
column.ValueMember = "Name";
column.ValueMember = "This";
column.DataSource = new List<SomeClass>(new SomeClass[]{new
SomeClass("Fred")});
If I don't do this I get a conversion exception as the datagridview
dutifully attempts to parse a string into an instance of "SomeClass".
Surely there is a better way around this than defining a property that
returns "this". Isn't there?
Simon Tamman
|