Binding DataGridView to DataTable with ComboBox not working
<p>I'm trying to create a DataGridView bound to a DataTable where one column is a ComboBox. The code runs but I get the following error after binding (not when data is bound): System.ArgumentException: DataGridViewComboBoxCell value is not valid.</p>

<p>In the DataGridView one of the columns is a DataGridViewComboBoxColumn that uses an enum (named structureType) as it's source:</p>

<pre><code>// ColumnStructure
// 
this.ColumnStructure.ValueType = typeof(structureType);
this.ColumnStructure.DataSource = Enum.GetValues(typeof(structureType));
this.ColumnStructure.HeaderText = "Structure";
this.ColumnStructure.Name = "ColumnStructure";
this.ColumnStructure.DataPropertyName = "Structure";
//
</code></pre>

<p>When I populate the DataGridView without using a DataTable, it works just fine:</p>

<pre><code>structureType? structure = GetStructure(part);
dgvObjectTypes.Rows.Add(name, type, structure, count);
</code></pre>

<p>Now I would want to use a DataTable instead, but can't get it to work. The DataTable is created as follows:</p>

<pre><code>DataTable table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Type", typeof(string));
table.Columns.Add("Structure", typeof(DataGridViewComboBoxCell));
table.Columns.Add("Count", typeof(int));
</code></pre>

<p>Other columns work great but I can't get the "Structure" column to work. Here's how I've tried to create the combobox:</p>

<pre><code>var cb = new DataGridViewComboBoxCell();
cb.ValueType = typeof(structureType);
cb.DataSource = Enum.GetValues(typeof(structureType));
cb.Value = (structureType)structure;
</code></pre>

<p>After that I just create the rows for the table and and set the table as datasource for the DataGridView:</p>

<pre><code>table.Rows.Add(name, type, cb, count);
dgv.DataSource = table;
</code></pre>

<p>I've read a lot of posts where it has been stated that using enums in comboboxes causes problems (this for example: <a href="https://stackoverflow.com/questions/17972291/datagridview-linked-to-datatable-with-combobox-column-based-on-enum">DataGridView linked to DataTable with Combobox column based on enum</a>), but that doesn't seem to be the case here. I even tried to use explicitly typed arrays of strings but still get the same error. I think I'm doing something wrong with the DataGridViewComboBoxCell.</p>

<p>What could be the problem?</p>