How do I remove the elipsis for a custom UITypeEditor that is read-only?
-
03-07-2019 - |
Question
I have two fields that are of the same type in my property-grid. However, one is read-only, the other is editable.
Both of these fields are of a custom type, and thus have a custom UITypeEditor, which puts the elipsis ([...]) button on the field.
[
CategoryAttribute("5 - Wind"),
DisplayName("Factored Area"),
Description("The factored area for the segment."),
EditorAttribute(typeof(umConversionTypeEditor), typeof(UITypeEditor)),
TypeConverter(typeof(umConversionTypeConverter)),
ReadOnly(true)
]
public FactoredAreaClass FactoredArea { ... }
[
CategoryAttribute("5 - Wind"),
DisplayName("Factored Area Modifier"),
Description("The factored area modifier."),
EditorAttribute(typeof(umConversionTypeEditor), typeof(UITypeEditor)),
TypeConverter(typeof(umConversionTypeConverter))
]
public FactoredAreaClass FactoredAreaMod { ... }
In this example, FactoredAreaMod is available to be edited, but BOTH have the elipsis, which will cause great confusion with the users. Any way to turn that off??
Solution
OTHER TIPS
Thanks to Jeff Yates, I came up with an alternate solution. Here's how I solved it...
The biggest issue was that the EditorAttribute was actually assigned in the FactoredAreaClass. I put it in the raw example just to show that there was an editor attribute assigned.
[
CategoryAttribute("5 - Wind"),
DisplayName("Factored Area"),
Description("The factored area for the segment."),
EditorAttribute(typeof(UITypeEditor), typeof(UITypeEditor)), // RESET THE UITYPEEDITOR to "nothing"
ReadOnly(true)
]
public FactoredAreaClass FactoredArea { ... }
[
CategoryAttribute("5 - Wind"),
DisplayName("Factored Area Modifier"),
Description("The factored area modifier."),
// the EditorAttribute and TypeConverter are part of FactoredAreaClass
]
public FactoredAreaClass FactoredAreaMod { ... }
The trick is not to use the Modal style when the bounded property is readonly. Luckily for us, the context is provided in the GetEditStyle method. A simple code will do the job:
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return context.PropertyDescriptor.IsReadOnly
? UITypeEditorEditStyle.None
: UITypeEditorEditStyle.Modal;
}