Custom sort order

Shell for WPF Forum

The latest build of this product (v2019.1 build 0685) was released 4 months ago, which was before this thread was created.
Posted 1 month ago by rex hui
Version: 19.1.0685
Avatar

I understand we need to override the WindowsShellService.CompareObjectsUsingProperty to provide the sort order.

I just couldn't figure out how to achieve this.

We have a special item that we want to stay at the top no matter which column is being sorted and in what order.

I see the ShellObjectItemAdapter.SortChildren is not overridable.

Could you please give me some idea?

Comments (10)

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rex,

The default sort comparer looks at the IShellObject.SortOrder property as its first comparison.  If you set that to -1 for the one object you want at the top, then I would think that's all you need to do to sort it there since the default of that property is 0 for everything else.


Actipro Software Support

Posted 1 month ago by rex hui
Avatar

Thanks for the suggestion. Setting the item's SortOrder to -1 works when the list is first loaded but if the user changes the sorting column or direction, the item will be at the bottom of the list.

So I will need to change SortOrder to -1 for ascending and to 1 for descending but I don't know where to do this?

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rex,

The ShellListView control has a ColumnHeaderTapped event that fires when a column header is tapped.  Can you update the SortOrder for that item in that event?


Actipro Software Support

Posted 1 month ago by rex hui
Avatar

I tried that but that doesn't work. The CompareObjectsUsingProperty happens before the ColumnHeaderTapped event .

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rex,

Yes it looks like the ShellListView.OnColumnHeaderTapped method ends up getting called right before you can handle the event yourself.  That protected virtual OnColumnHeaderTapped method is where it does the sort toggle.  You could probably override that method in an inherited class and put your logic there instead, then call the base.OnColumnHeaderTapped method.


Actipro Software Support

Posted 30 days ago by rex hui
Avatar

Thanks but that doesn't work.

It seems the sorting is only done if you tap on a different column so the CompareObjectsUsingProperty is not being called.

Posted 29 days ago by rex hui
Avatar

I figured out that I can force the sorting by raising the ShellObjectChangeKind.SortRequested event.

This seems to work now.

Posted 27 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rex,

Ah yes, if you are simply reversing the sort order on the currently-sorted column, it will flip the order of the items instead of calling for a full re-sort.  That's a performance optimization.  While OnColumnHeaderTapped is still called in that scenario, the CompareObjectsUsingProperty method isn't called in that case.


Actipro Software Support

Posted 27 days ago by rex hui
Avatar

Another thing I noticed is the default SortDirection when it is null is different on each column. What determines the default value for that?

Posted 27 days ago by rex hui
Avatar

Sorry, Nevermind, I found there is a ColumnDefaultSortDirection

Add Comment

Please log in to a validated account to post comments.