I have a list of
Customer objects(List<Customer>) bound to a DataGridView. One property of Customer is
Category which itself is an object of type
Category. I want to bind this property to a
DataGridViewComboBoxColumn column.
At design time, I add a
DataGridViewComboBoxColumn column to the DataGridView. I set the following properties of this column.
| |
(pseudo code) DataPropertyName = "Category" DataSource = CategoryBindingSource DisplayName = "Name" ValueMemeber = (blank) |
The
BindingSource CategoryBindingSource is bound to a
List<Category> object. But when I run it, I got two errors for each row for the DataGridView. The context is
Formatting and
Display. The error message is the
cell value is not valid.
Then I go to debug mode, and find the cell's ValueType is string instead of Category. Why is it like that?
Then I add a
CategoryId property in the
Customer class which is a Guid. This time I set the following properties of the combo column.
| |
(pseudo code) DataPropertyName = "CategoryId" DataSource = CategoryBindingSource DisplayName = "Name" ValueMemeber = "Id" |
Now it can run without an error. But I find the combo column cannot be dropped down. In fact, the data source
List<Category> object contains two Category objects.
Does anybody has any experience with binding a DataGridViewCobmoColumn to a complex object (Category in my case) instead of a primitive data type (like Guid CategoryId)? Do I have to add a CategoryId just for this problem?
Thanks!