I was working on my bachelor degree project (a code generator for Atmega16) these days and found myself having a nasty enum/combobox problem.
I usually map a enum directly to the data source of a combobox. Unfortunately for the enum below, it didn't look the way I wanted:
I wouldn't want for the user to see the leading underscore. Furthermore, I wanted to find a solution in which I could display instead of _16k something like 16000 Cycles without complicating myself too much.
I did some research and I found a solution here. Stated briefly, you need to derive a class from TypeConverter (see the implementation I found here) and start writing your enums like this:
The main idea is that if you use a TypeConverter, you can break the dependency between the name of the enum and what's displayed in your combobox.
I usually map a enum directly to the data source of a combobox. Unfortunately for the enum below, it didn't look the way I wanted:
![]() |
Ugly mapping |
I did some research and I found a solution here. Stated briefly, you need to derive a class from TypeConverter (see the implementation I found here) and start writing your enums like this:
![]() |
Good-looking mapping |
In case you didn't knew, here's how you map an enum to a combobox and set/get the selected item::
Q: Do you know other (better/simpler) methods for mapping enums to comboboxes? Leave me a comment, if so.
See here the example source files
Download here the entire C# code examples collection
Read more about this topic:
http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx
No comments :
Post a Comment