How can I set order of PropertyGridPropertyItem?

Grids for WPF Forum

Posted 15 years ago by RredCat - Ukraine
Avatar
I create a category item (PropertyGridCategoryItem) and add there PropertyGridPropertyItems. Property items are sorted by name. How can I set myself order?

Comments (10)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You would need to clear/customize the PropertyGrid.SortDescriptions collection. By default, the sort descriptions put categories before properties, then sort by name. If you remove the second sort description (the one that sorts by name), then the order you define the properties would be preserved.


Actipro Software Support

Posted 15 years ago by RredCat - Ukraine
Avatar
It helped when I clear.. How can I do it through xaml?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It is not currently possible to clear the SortDescriptions (or any collection for that matter) using XAML.


Actipro Software Support

Posted 15 years ago by Ken Elmy
Avatar
I did this (removed the second sort description) and while it's no longer sorting by name it is not sorting in the order the properties are written in the xaml. I can't determine the order as it appears to be somewhat random. For example in one PropertyGridCategoryItem I have 4 PropertyGridPropertyItems. In the xaml they are written in this order

    prop 1, "Name Z", ValueTemplate
    prop 2, "Name A", CheckBoxValueTemplateKey
    prop 3, "Name B", CheckBoxValueTemplateKey
    prop 4, "Name C", CheckBoxValueTemplateKey
Without deleting the SortDescription at runtime they are rendered like this (as expected):

    prop 2, "Name A", CheckBoxValueTemplateKey
    prop 3, "Name B", CheckBoxValueTemplateKey
    prop 4, "Name C", CheckBoxValueTemplateKey
    prop 1, "Name Z", ValueTemplate
When I delete the second SortDescription it appears like this:

    prop 3, "Name B", CheckBoxValueTemplateKey
    prop 4, "Name C", CheckBoxValueTemplateKey
    prop 1, "Name Z", ValueTemplate
    prop 2, "Name A", CheckBoxValueTemplateKey
What am I missing here?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Ken,

If you can send over a small sample project to our support address, then we can take a look.


Actipro Software Support

Posted 15 years ago by Ken Elmy
Avatar
I'll try and post something tomorrow -- deadlines... Thanks for the quick response.
Posted 15 years ago by Kelly Leahy - Software Architect, Milliman
Avatar
Sorting in .NET is not 'stable' for the framework's implementation of sort, so what you're probably seeing is the effects of sort not being stable sort. Are you using categorized values? If so, you might be best to use PropertyGridPropertyItem.Tag to specify an 'absolute' sort order and then change the sort collection to contain Category & Tag as the sort descriptions instead of Category & Name.

In case "stable sort" doesn't mean anything to you, what it basically means is this:

if you have a list with

Category Name
X X_first
X X_second
X X_third
Y Y_first
Y Y_second

and you sort only by Category, there is not guarantee what order the items within categories X and Y will come, only that all X's will appear before all Y's do.

The .NET framework's sort algorithm is like this (makes no guarantees about preserving the order), whereas a stable sort makes the guarantee that items are left in the same order they started in, if they are equal in the key columns.

Kelly Leahy Software Architect Milliman, USA

Posted 15 years ago by Ken Elmy
Avatar
Thanks Kelley. That's exactly the implementation I had actually used the day after I posted this. Sorry I guess I should have closed out the post when I discovered the workaround. I hope Actipro adds a property to the control that would either serve as the definitive sort order or provide a sort description that implements a "sort as written" order.
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Ken,

We are hoping to address issues like this after we get WPF Studio 5.0 out.


Actipro Software Support

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Ken,

We are hoping to address issues like this after we get WPF Studio 5.0 out.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.