views:

1792

answers:

2

Hello

So, I have a DataGridView using as datasource a BindingList

DataGridView.DataSource = new  BindingList<Car>{...}

Where

public class Car
{
    public ColorName Color { get; set;}
}

with

public class ColorName
{
    public int Id {get; set;}
    public string Name{get; set;}
}

and I use a Combobox column:

DataGridViewComboBoxColumn colorNameDataGridViewTextBoxColumn;
colorNameDataGridViewTextBoxColumn.DataPropertyName = "Color";
colorNameDataGridViewTextBoxColumn.HeaderText = "Color";
colorNameDataGridViewTextBoxColumn.Name = "Color";
colorNameDataGridViewTextBoxColumn.DisplayMember = "Name";
colorNameDataGridViewTextBoxColumn.ValueMember = "Id";
colorNameDataGridViewTextBoxColumn.DataSource = new ColorName[] {...};

How can I get this to work ?! Now I get an exception because I think it tries to cast the Id to ColorName.

I tried with an empty ValueMember or adding a direct cast operator to ColorName class but can't get it to work.

Sure I can use an int in the Car class to represent the color but is not as nice.

As you probably guessed those classes are in fact Castle Project ActiveRecord-s.

Any ideas are welcome !

+3  A: 
Marc Gravell
A: 

I wasn't sure it was going to work in edit mode but it works ! Very clever, thank you !

Catalin DICU