Sorting categories

Grids for WPF Forum

Posted 8 years ago by Mike Berriman
Version: 11.1.0543
Avatar
I have followed the instructions in this post on how to sort categories. I have overridden GetDataAccessors in my factory class with the following :

public override IList<AC.Primitives.IDataAccessor> GetDataAccessors(object[] values, AC.Primitives.DataFactoryOptions options)
{
  List < AC.Primitives.IDataAccessor > list = List<AC.Primitives.IDataAccessor>)base.GetDataAccessors(values, options);

  if (list != null)
  {
    list.Sort(comparer);
  }
  return list;
}
Where comparer is my custom sort order. The list that is returned from this function is sorted the way I want it to (ie my comparer is working) however, the output in the property grid is not in the same order.

Am I missing something in regards to sorting these categories?

Comments (2)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mike,

There are actually two ways to sort the items displayed by the PropertyGrid. The PropertyGrid will sort everything returned from the DataFactory based on the SortDescriptions and SortComparer property, with the latter taking precedence. By default, there are two sort descriptions defined which sort categories before properties, and then everything alphabetically. You can disable these default sort descriptions by setting AreDefaultSortDescriptionsEnabled to false.

Assuming there are no sort descriptions or comparer defined, then the order of the items is determined by the DataFactory. What ever order it returns the items will be the order they are defined. So in your case, you probably need to set AreDefaultSortDescriptionsEnabled to false or have set SortDescriptions/SortComparer.

That aside, we have actually added a QuickStart that shows how to define and use a custom SortOrderAttribute and CategorySortOrderAttribute since that forum post, called "Sorting w/ Custom Attribute QuickStart".


Actipro Software Support

Posted 8 years ago by Mike Berriman
Avatar
Problem solved. User error. I had implemented a SortComparer, but thought it only did properties, not categories, and so coded it (erroneously) as such. Obviously this means that my call to GetAccessors was sorting things correctly, and then my SortComparer was resorting them incorrectly.

I have now modified the SortComparer to work on both properties and categories, and it works fine.

Cheers.
The latest build of this product (v2019.1 build 0683) was released 12 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.