StrataFrame Forum

Sorting Listview

http://forum.strataframe.net/Topic10568.aspx

By Mark Dowlearn - 7/26/2007

My experience thus far indicates that in a when a field is processed within a listview so that it includes a format string or uses the "PopulatedThroughEvent" method, the sorting does not accurately reflect the base value.

For example, if I'm sorting on a name column and want to add a format string (<a href= "... ) to make the name be a link when viewed on the web page, the sorting gets messed up and does not display the list properly.

Has anyone else experienced this also?  If it's by design, then I request that the design be changed <smile>.

At least in the case of creating a hyperlink, I would have expected that the sorting would still be on the base value of the field (or whatever the displayed text of the link is if the two are not the same), but this does not appear to be the case.

By StrataFrame Team - 7/26/2007

The basic ListViewItemSorter in the framework can only see the text values of the ListViewItems in the ListView.  The sorter does not know about the data.  So, if you want to be able to sort off of the data and not the text within the view, then you'll have to write your own sorter.  The ListViewItemSorter property of a list view just accepts an IComparer object, which is easy enough to implement.
By Mark Dowlearn - 7/26/2007

Hello, Ben - thanks.

I guess if that's the case, I'm wondering if a feature request for the framework would be to have a flag property on the ListView item that indicates the framework should parse the format string (or the DisplayValue set in a RowPopulating event) for just the displayed text rather than the entire string that includes markup and then use that for the sort functionality.

By Trent L. Taylor - 7/27/2007

Actually it will already do this intrinsically for a Date or Date/Time value.  As Ben mentioned above, we have a ListViewItemSorter class that you can implement as the ListViewSorter on a ListView.  This class, which you can look at since you get the source, is an IComparer implementation which sorts on character data while testing for date values and sorting correctly there.  If you need more functionality, it is very easy to write a comparer class as there is only a single method that you have to write that compares two values to see which one should rank higher.  You can also look at the ListViewItemSorter class to see what we did and you can expand on that if you have the need.  This would be your fastest solution.
By Chan - 7/29/2007

Hi,

How to do this for browseresult? Which event to handle? Any sample for ListViewItemSorter class?
By StrataFrame Team - 7/30/2007

Yes, there is a ListViewItemSorter sample in the AdvancedListView sample (it might also be called SampleListViewPopulation). 

As for the BrowseDialog, I don't know that there is a way change the sorting on the BrowseDialog.  It currently uses the default ListViewItemSorter and the events have not been exposed for you to override the sorter that is used.

By Chan - 7/30/2007

Hi,

Thank you for reply.



Hope you could provide some way to overcome this very soon, because my customer complaint that current date field sorting by ASCII is not making any sense.



Thank you