简体   繁体   中英

How to use a custom UITypeEditor for an enum?

I wrote a custom UITypeEditor for my type Smiley per MSDN's walkthrough http://msdn.microsoft.com/en-us/library/ms171840.aspx

When the user clicks the ellipsis, my UITypeEditor will launch a modal dialog box.

public class SmileyEditor : UITypeEditor
{
    public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }

After MUCH PAIN I found it works if my type is a Class, but not if it's an enum. What's going on?

    [Editor(typeof(SmileyEditor), typeof(System.Drawing.Design.UITypeEditor))]
    public Smiley face { get; set; }

If the type Smiley is an enum, then the property grid doesn't show the ellipsis button, just a drop down. Why?

Apparently when a system type editor exists, PropertyGrid prefers it over one's custom editor. A workaround is to annotate your type with a TypeConvertorAttribute, referencing a TypeConvertor that overrides the method GetStandardValuesSupported . See https://stackoverflow.com/a/4067173/284795

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM