I'm trying to use a ComboBoxColumn in a DataGridView to allow editing of an enum value in a class. E.g
public enum Stuff { Apples, Pears, Oranges } public class MyTestClass { public Stuff MyStuff { get { return m_MyStuff; } set { m_MyStuff = value; } } public string MyString { get { return m_MyString; } set { m_MyString = value; } } private Stuff m_MyStuff = Stuff.Apples; private string m_MyString = "Test"; public test() { } } |
So I want to use a DataGridView to display a BindingList<MyTestClass> where the first column is a text column and the second is a drop down that lets the user select the type of "Stuff" they want.
I've tried for a long time to get this to work but without any luck! I tried manually setting the .Items property of the drop down column to all of the values in "Stuff", which results in value not found exceptions and various other issues. I've tried creating a dataTable that contains a row for each of the values in the Stuff Enum but, again, more value not found and other exceptions.
Is there a simple way to get this to work the way I want I'm using a binding source for the data grid view which is bound to MyTestClass.
Thanks,
Koni

DataGridViewComboBoxColumn and Enum values
rhaazy
There just happens to be a help topic on binding the DataGridView combobox column to enum values: http://msdn2.microsoft.com/en-us/library/y0wfd4yz.aspx I don't know if it works with Beta2. There were a lot of bugs fixed since then.
(EDIT: updated link)
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
vijay_jan80
comboBox1.DataSource = Enum.GetValues(typeof(Stuff));
Greg Wishart
BTW this is with Beta2.
Reaper069
Hi Mark, I checked out that article but It doesn't appear to be related to combo grid elements and enum values, is the link correct
Thanks
e2e
-mark
DataGridView program Manager
Microsoft
This post is provided "as-is"
Moinuddin
Thanks Mike, this cuts out a few lines of code and is much neater than looping through the enum values and adding them by hand.