1

I'm trying to make a manually-editable DataGridView, not bound to any DataSource, where the DataGridView itself and most of the cell types are subclassed (custom cell types are provided as templates to columns in the grid subclass) so that certain events can be handled differently for different cell types.
One of the custom cell types is based on a ComboBoxCell, where the Items are manually added from an enum. At the moment, this is the only part of the application which isn't working properly, so I assume I got most of the subclassing syntax okay (I'm new to C#).
Whenever I run the application and try to change the dropdown list to anything other than the blank default, a message box appears which includes the line:

System.ArgumentException: DataGridViewComboBoxCell value is not valid.

As I understand, this happens because the cell's Value is set as a string instead of an object. I've tried fixing this by setting the Value to the string's value in the OnEndEdit event, which caused the error window to only appear once and the dropdown to be selected properly only after the window was dismissed.
I've also tried overriding the event that throws DataError and managed to cause the error window not to appear, but this way is considered a hack and won't be accepted as a solution - I need to stop whatever error is being thrown from appearing entirely.
Any suggestions as to what other events I should override, or how else to stop this error?

MASQ
  • 135
  • 15

1 Answers1

0

In the DataGridViewComboBoxColumn class, there is a ValueType property that allows you to define the type of the data you add in the Items collection.

You could use it this way :

myComboBoxColumn.ValueType = typeof(myEnum);
Bioukh
  • 1,888
  • 1
  • 16
  • 27