0

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:

enter image description here

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:

enter image description here

Dis I miss something simple?

Community
  • 1
  • 1
AJ29
  • 1,381
  • 10
  • 10
  • 2
    You can't do this, the Property Grid just doesn't work like that. The button for modal or dropdown editors appears only when the item is selected. – Simon Mourier Feb 09 '14 at 08:08
  • Ok thanks! I've seen a software where they did it and it looked a lot like a propertygrid but maybe it was a custom one... – AJ29 Feb 09 '14 at 13:43

0 Answers0