Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1735
Sorting of expanded collection items
posted

Hi,

I have a collection of points that I display in the property grid using a custom PointCollection class that implements the ICustomTypeDescriptor interface. This is the same way as the samples browser implements corresponding functionality. The PointCollection class adds the individual points to the properties' list in a standard way as follows, with the source collection index as an input:

public PropertyDescriptorCollection GetProperties()
{
    var pds = new PropertyDescriptorCollection(null);
 
for (int i = 0; i < this.Count; i++)
 
{
        pds.Add(new PointCollectionDescriptor(this, i));
  
}
    return pds;
}

The PointCollectionDescriptor constructor looks more or less like this:

public PointCollectionDescriptor(PointCollection col, int idx)
 
: base("#" + (idx + 1), null)
{
    this.collection = col;
    
...

}

The output in the property grid is given in the attached image. As we can see from the image, the individual points seem to be sorted by name by the property grid, even though they are added in proper order in the PropertyDescriptorCollection. Item '#10' should be at the bottom of the list, not as item 2.

How can I get the sort order correct?

I have tried to fix this by overriding the PropertyDescriptorCollection class with an implementation that implements the various sorting methods, and tried using this class instead in the code snippet above. However, when I do this the sorting methods are never called by the property grid!

Regards,
Leif

Parents
  • 17475
    Offline posted

    Hello and thank you for posting!

    I have been looking into your description and the provided code snippets and I am not sure what might go wrong with the custom comparer that you are using. Would it be possible to share the comparer code or a sample application so I can investigate it for you? Thank you in advance.

Reply Children