<p>I currently have a class and I'm trying to create an easy GUI to create a collection of this class. Most of the attributes of this class are strings. However, one of the attributes I want the user to be able to set is an Enum.  Therefore, I would like the user interface, to have a dropdownlist for this enum, to restrict the user from entering a value that is not valid. Currently, I am taking the initial list of objects, adding them to a DataTable and setting the DataSource of my DataGridView to the table.  Works nicely, even creates a checkbox column for the one Boolean property. But, I don't know how to make the column for the enum into a dropdownlist. I am using C# and .NET 2.0.</p>

<p>Also, I have tried assigning the DataSource of the DataGridView to the list of my objects, but when I do this, it doesn't help with the enum and I'm unable to create new rows in the DataGridView, but I am definitely not bound to using a DataTable as my DataSource, it was simply the option I have semi-working.</p>

[{'answer_id': 56483, 'author': 'Ozgur Ozcitak', 'author_id': 976, 'author_profile': 'https://Stackoverflow.com/users/976', 'pm_score': 6, 'selected': True, 'text': '<p>I do not know if that would work with a DataGridView column but it works with ComboBoxes:</p>\n\n<pre><code>comboBox1.DataSource = Enum.GetValues(typeof(MyEnum));\n</code></pre>\n\n<p>and:</p>\n\n<pre><code>MyEnum value = (MyEnum)comboBox1.SelectedValue;\n</code></pre>\n\n<p>UPDATE: It works with DataGridView columns too, just remember to set the value type.</p>\n\n<pre><code>DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();\ncol.Name = "My Enum Column";\ncol.DataSource = Enum.GetValues(typeof(MyEnum));\ncol.ValueType = typeof(MyEnum);\ndataGridView1.Columns.Add(col);\n</code></pre>\n'}, {'answer_id': 56613, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>Or, if you need to do some filtering of the enumerator values, you can loop through <code>Enum.GetValues(typeof(EnumeratorName))</code> and add the ones you want using:</p>\n\n<pre><code>dataGridViewComboBoxColumn.Items.Add(EnumeratorValue)\n</code></pre>\n\n<p>As an aside, rather than using a DataTable, you can set the DataSource of the DataGridView to a BindingSource object, with the DataSource of the BindingSource object set to a <code>BindingList&lt;Your Class&gt;</code>, which you populate by passing an <code>IList</code> into the constructor.</p>\n\n<p>Actually, I'd be interested to know from anyone if this is preferable to using a DataTable in situations where you don't already have one (i.e. it is returned from a database call).</p>\n"}]
['https://Stackoverflow.com/questions/56443', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4660/']