Ray White
Ray White

Reputation: 337

AutoComplete in WinForms .NET PropertyGrid using UITypeEditor Dropdown

How can I get AutoComplete with WinForms .NET PropertyGrid while using a custom UITypeEditor Dropdown list?

I want users to type into the WinForms .NET PropertyGrid combobox edit field, and automatically select an item from my custom dropdown.

As you can see from the code snippet and screenshot below, I am using a derived UITypeEditor class to host a custom dropdown list in the PropertyGrid.

I want to somehow capture text from the PropertyGrid combobox TextChanged event, and use that to select an item in my custom dropdown. I assumed that the PropertyGrid does not naturally provide this functionality, and that I would have to employ some trickery to achieve it. It just don't know how.

My custom C# class:

class UIDropdownTypeEditor : UITypeEditor
{
    private IWindowsFormsEditorService _editorService = null;
    TypeConverter.StandardValuesCollection _list = null;

    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        // drop down mode
        return UITypeEditorEditStyle.DropDown;
    }

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
        _editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

        // Use a list box
        ListBox lb = new ListBox();
        more...
        more...

        // Show dropdown
        _editorService.DropDownControl(lb);
        return lb.SelectedItem;
    }
}

enter image description here

Upvotes: 1

Views: 85

Answers (0)

Related Questions