views:

732

answers:

2

How can I customize the sorting of categories in a PropertyGrid?

If I set either of the following...

propertyGrid.PropertySort = PropertySort.Categorized;
propertyGrid.PropertySort = PropertySort.CategorizedAlphabetical;

... then the categories will be alphabetized. ("Alphabetical" would seem to apply to the properties within each category.) If I use PropertySort.NoSort, I lose categorization.

I'm populating my PropertyGrid with SelectObject, which is pretty easy:

this.propertyGrid1.SelectedObject = options;

options is an instance of a class with suitably decorated properties:

    [CategoryAttribute("Category Title"),
    DisplayName("Property Name"),
    Browsable(true),
    ReadOnly(false),
    BindableAttribute(true),
    DesignOnly(false),
    DescriptionAttribute("...")]
    public bool PropertyName {
        get {
            // ...
        }

        set {
            // ...
            this.OnPropertyChanged("PropertyName");
        }
    }

I have a few dozen properties in half a dozen categories.

Is there some way I can adjust the category sort order while preserving my ease of use with SelectedObject?

+3  A: 

If you mean that you want the categories sorted in a specific (non-alphabetical) way, then no - I don't think you can do that. You might want to try VisualHint - I expect it does have this (since you can seize a lot more control).

Marc Gravell
+1  A: 

I think this link is useful http://bytes.com/groups/net-c/214456-q-ordering-sorting-category-text-propertygrid

The final trick in that is pure evil genius ;-p Nasty, but if it gets the job done....
Marc Gravell