Question

I'd like to implement autocomplete string field in PropertyGrid, that can be set to custom value.

Here is my string converter

public class EntityNameAutocompleteConverter : StringConverter
{
    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    {
        return true;
    }

    public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
    {
        return false;
    }

    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    {
        return new StandardValuesCollection(Globals.EntityCache.Select(e => e.Name).ToList());
    }
}

and I set it as TypeConverter for the string property to be edited.

The problem is that there may be a lot of standard values. So I'd like to filter them by input, e.g. if I have entered "Foo", I will see only strings, that starts from "Foo" in the dropdown.

Is that possible in any way? Maybe it is possible to get intermediate value of property from context or in any other way?

Was it helpful?

Solution

You can use the context parameter and get the current property value, something like this:

public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
    // get the current property value
    string value = (string)context.PropertyDescriptor.GetValue(context.Instance);
    return new StandardValuesCollection(GetFilteredList(value));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top