Change expandable property root text on click

75 views Asked by At

I have a PropertyGrid with Expandable Properties. It looks like this:

https://i.stack.imgur.com/zqnjk.jpg

It displays the Value and the Measurement Unit. Now, if the user writes in a double value in the root row, the Value property will change, everything else stays unmodified.

I want that if the user clicks in the root row, its text ("5 EUR" on the picture) would change to show only the Value ("5"). But if the user doesn't click in, the text would stay unmodified ("5 EUR").

Now my ExpandableObjectConverter looks like this (only the relevant part):

ObjectProperty oldOP;

public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
    if (destinationType == typeof(ObjectProperty))
    {
        return true;
    }

    return base.CanConvertTo(context, destinationType);
}

public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
    ObjectProperty op = (ObjectProperty)value;
    oldOP = op;
    return op.ValueProp.ToString() + " " + op.MUProp.ToString();
}

public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
    if (sourceType == typeof(string))
        return true;

    return base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
    ObjectProperty op;
    double newValue;
    if (double.TryParse((string)value, out newValue))
    {
        op = oldOP;
        op.ValueProp = newValue;
        return op;
    }
    else
    {
        op = oldOP;
        return op;
    }
}
0

There are 0 answers