Error: "DataGridViewComboBoxCell value is not valid." DataSource is list of basic type
c#, datagridview
Solution
I found the answer here. It's also mentioned in this answer to the second link in my question. When setting the `DataSource` to a list of anything that's not a string, set the `ValueType` of the column to `typeof(<your data type>)`
IList<double> kvChoices;
// Populate kvChoices...
DataGridViewComboBoxColumn kvCol =
dataGridView1.Columns[0] as DataGridViewComboBoxColumn;
kvCol.DataSource = kvChoices;
kvCol.ValueType = typeof(double);
Problem
I couldn't find a question on SO that exactly matched my problem. Similar to this question and this question, I'm setting the `DataSource` on a `DataGridViewComboBoxColumn` to a list of things. In my case the things are simple types like doubles and ints, so the answers talking about ValueMembers and DisplayMembers don't do me a lot of good. When the user selects a value I get the dreaded "DataGridViewComboBoxCell value is not valid" error. I could swallow the error with an empty dataGridView_DataError handler, but that is obviously a bad way to go.