Question

I have a PropertyGrid, unsorted.

One object is an object that inherits from another class:

[TypeConverter(typeof(ExpandableObjectConverter))]
public class ExpandValues: Values
{
    public double Value2 { get; set; }

    public ExpandValues()
        : base()
    {

    }
    public ExpandValues(string name, double value1, double value2)
        : base(name, value1)
    {
        Value2 = value2;
    }
}

Parent class:

[TypeConverter(typeof(ExpandableObjectConverter))]
public class Values
{
    [Browsable(false)]
    public string Name { get; set; }
    public double Value { get; set; }

    public Values()
        : this(null, 0)
    {

    }
    public Values(string name, double value)
    {
        Name = name;
        Value = value;

    }
}

When I open the object that contains the class ExpandValues is showing me the values ​​like this:

Value2
Value

Is there a way for me to tell him first display the objects of the parent class (without making the PropertyGrid sorted?)

Was it helpful?

Solution

For the values ​​to be in order, I override the variable value of parent class:

I added a virtual to a variable in parent class:

public virtual double Value { get; set; }

Then I override him:

[TypeConverter(typeof(ExpandableObjectConverter))]
public class ExpandValues: Values
{
    public override double Value
    {
        get
        {
            return base.Value;
        }
        set
        {
            base.Value = value;
        }
    }

    public double Value2 { get; set; }

    public ExpandValues()
        : base()
    {

    }
    public ExpandValues(string name, double value1, double value2)
        : base(name, value1)
    {
        Value2 = value2;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top