How to keep UITypeEditor visible in PropertyGrid when object is not selected?
-
08-10-2022 - |
Pregunta
I'm writing a C# Windows form program and I'm having a hard time with PropertyGrids and UITypeEditor... I've read this post already: How to create custom PropertyGrid editor item which opens a form? which helped me getting started.
Here's the basic code I've got so far:
public FooClass Foo { get; private set; }
[Editor(typeof(FooEditor), typeof(UITypeEditor)),
TypeConverter(typeof(FooType))]
public class FooClass
{
private bool _enabled;
public bool Enabled
{
get { return _enabled; }
set { _enabled = value; }
}
public void ShowWindow()
{
using (var test = new Form())
{
test.ShowDialog();
}
}
}
private class FooType : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
return "Click on the button to show the window";
}
}
private class FooEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
var svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
var foo = value as FooClass;
if (svc != null && foo != null)
{
foo.ShowWindow();
}
return null;
}
}
That works as expected: when the Foo object is selected in the propertygrid I see the "..." button on the right, I click and the window shows up:
What I can't figure out is how to make this "..." button stay visible even when the Foo object is not selected in the propertygrid:
Dis I miss something simple?
No hay solución correcta
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow