How to "humanize" enum names in property grids?

Grids for WPF Forum

Posted 4 years ago by Chris Carter
Version: 14.2.0611

I'd like to do this: I have no idea whether I should include that link's content here for future viewing. Basically, I have some PropertyGridItems for enum values, but the real names of the enum values are not for human consumption. For example, one is oz_avdp but the customer doesn't want the information about which specific ounce specification is used; it should be displayed as oz.

The documentation for EnumListBox says:

By default, the enumeration values will be displayed using a string-representation of the defined field names. A custom TypeConverter can be defined that will look for a DescriptionAttribute defined on the fields, and use that in place of the field name. This allows user friendly strings to be used and also supports localization.

I don't know whether PropertyGridItem uses EnumListBox for enums, but even if so I'm not sure this is the way for me to go. My enums are deep in the model, and it doesn't seem appropriate to use a System.ComponentModel type there. Then again I've already disregarded that concern in another case for a big gain in terms of less code.

What should my approach be here?

Comments (3)

Answer - Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Chris,

The EnumEditBox can be used as an editor for PropertyGrid but since Editors is a separte product from PropertyGrid, it's not used by default.  If you look at the "PropertyGridIntegrationInterop" demo in the Editors section of the Sample Browser project, you can see where EnumPropertyEditor is referenced.  If you set its UseDescriptionAttributes property to true, then it will look for DescriptionAttribute to use for the visible text.  That's the easiest way to go but you will have to use DescriptionAttribute.

The other option is to make a custom property editor that has EnumEditBox in it and set the EnumEditBox.StringValueConverter property to a custom converter that would have the logic you need in it.  The PropertyGrid "CustomPropertyEditor" QuickStart shows how to make a custom properly editor in general.

Actipro Software Support

Posted 4 years ago by Chris Carter

Hmm, can EnumPropertyEditor show a static list of radio buttons rather than a dropdown? I think that's the only issue I still have.

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA

No, you'd need to make a custom property editor that used EnumListBox in its template if you want that look instead.

Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 10 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.