Hi may i know how to get the enum value below to bind into the combobox? I wrote the below code which works well but wonder is this the best way.
public enum Cou
I don't think there is a best way. I used to do something similar with a GenericListItem
class where T is the backing value, in your case, an enum.
This class exposed Display
string and Value
T properties to bind to. I think I was also overriding ToString
because it is the default if you don't specify the DisplayMember
. I went further and made a constructor taking just Value
and defaulting Display
to Value.ToString
, which in the case of enums works I think.
I'd then make a List
, feed that into the DataSource
of the column and set the DisplayMember
and ValueMember
properties accordingly in code. This list is the alternative to the dictionary used in your example.
But I'm not saying it's a better solution :-) however it means you can remove code, say enum iteration, into this class or specialise the class for handling certain data types better, all with the end goal of being inserted into a list and bound to a control.