SanVEE
SanVEE

Reputation: 2070

How to implement sub category elements in Property Grid using C#

Is there any way to implement sub category elements in the Property Grid,

enter image description here

I have tried the following code but it doesn't seem to work

public class test
{
    private Min2Max range;

    [Category("Product")]
    public Min2Max Range
    {
        get { return range; }
        set { range = value; }
    }

    class Min2Max
    {
        private double min = 0.1;
        private double max = 99.9;

        public double Min
        {
            get { return min; }
            set { min = value; }
        }

        public double Max
        {
            get { return max; }
            set { max = value; }
        }
    }
}

any suggestions or help would be much appreciated, many thanks..:)

Upvotes: 1

Views: 2393

Answers (1)

Nicolas Cadilhac
Nicolas Cadilhac

Reputation: 4745

What you show in red in not a kind of subcategory but a property that has other child properties. The problem is that your Min2Max class and Range property are private, so the grid won't map them. If you fix this you will also need to attach to one of them a TypeConverter that "shows" the properties. At the very least, ExpandableObjectConverter can do it. If you need to enable editing the Range by itself (not its sub-properties), then your converter will have to take care of that too.

If you are more after a true subcategory, then Simon is right. It's not possible with the stock Microsoft PropertyGrid and you will have to rely on a 3rd party PropertyGrid.

Upvotes: 1

Related Questions