Click here to Skip to main content
15,886,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi experts,

the central part of an application I'm working on is where User can select multiple objects and change some of their properties' values. The UI for that is a PropertyGrid[^].

The objects live in an inheritance hirarchy, some being siblings of each other. Some are composed of other objects that can publish editable properties as well. Those sub-objects' UI are other PropertyGrids arranged in a TabControl-like manner using DockPanelSuite[^].

Should User select multiple objects, they are merged into one grid. So setting one value affects all selected objects (and differing values cause the value space to be left empty, just as we all know it from VS).

Sub-objects of multi-selected objects get merged with sub-objects of equalling type (in the sense of the application, not type as in System.Type). But they are separated into several grids as per their function within the application suggests.

Property names are nicely translated for foreign users by the objects implementing ICustomTypeDescriptor[^]. In fact, they all inherit from a "TranslatableBase" base class.

Non-numeric values are also translated by custom TypeConverter[^]s.

This has already gotten far too long, I fear.

Now my problem: Within each PropertyGrid, the alphabetical sorting doesn't work.

The sequence of properties as displayed is not alphabetical, nor the same as properties are defined in source.

[Edit]
The sorting doesn't match the property names (before the translation) either.
[/Edit]
[Edit2]
Having the PropertySort[^] property set to Alphabetical[^] works for a single selected object, but not for multi-selection.
[/Edit2]

Is there something one has to adhere to so that sorting works?
Posted
Updated 14-Oct-13 3:21am
v3
Comments
BillWoodruff 13-Oct-13 8:50am    
I don't pretend to understand your complex project and its architecture, and what your application actually does, but it sounds very impressive :)

Assuming you successfully put up a PropertyGrid showing the items you selected: are you saying the Alpha-sort feature of the PropertyGrid is not working ?
lukeer 14-Oct-13 3:59am    
Yes, exactly.

I wrote that lengthy description hoping that someone would recognize an aspect that is likely to cause the problem.
BillWoodruff 14-Oct-13 7:46am    
Hi, Wish I could be more helpful. If I remember correctly, this CP article from 2009 was very useful the last time I had to work directly with the PropertyGrid: http://www.codeproject.com/Articles/23242/Property-Grid-Dynamic-List-ComboBox-Validation-and
Sergey Alexandrovich Kryukov 14-Oct-13 15:44pm    
Yes, customizing the behavior of PropertyGrid is done by substitution of the reference to every target object with some relevant implementation of ICustomTypeDescriptor, and this is not easy, for all non-trivial implementations. This can be done using reflection. This activity is not so easy, partly due to awkwardly designed System.ComponentModel (in contrast to most other parts of .NET FCL.)

However, when I did such a thing, I never faced the problem of sorting. So, the only thing which could help is some highly simplified sample code developed by OP which would reproduce the problem.

Lukeer, could you do such thing? Otherwise you hardly could get any help. And I'm not sure that you can get help even if you make a perfect sample manifesting this problem, but perhaps you will care to try... :-)

—SA
lukeer 15-Oct-13 2:23am    
I tried that, but failed miserably. The test project always sorts as expected.

But I found the solution to my problem and posted it. Have a look and thanks.

1 solution

Got it!

I had read that all of PropertyGrid[^]'s built-in sorting had to be switched off (NoSort[^]) and instead ICustomTypeDescriptor[^]'s GetProperties[^] method should be designed to return the properties in the desired order.

What I had overlooked was that the applied Sort()[^] method doesn't sort the PropertyDescriptorCollection[^] that it is called upon, but returns a sorted new instance.

Just that missing assignment caused the sorting not to work. And my custom IComparer[^] sorting method didn't even get called when in should have been. It does now so I assume that the call was optimized away because the result was not used anyway.

Thank you guys for all your suggestions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900