Sorting dates in ListView


Author
Message
Juan Carlos Pazos
Juan Carlos Pazos
StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)
Group: Forum Members
Posts: 144, Visits: 227
Hi

I have a ListView that works fine, except in one thing.

If I click on any column header the data sorts fine, in numbers and text, but some columns has dates and here the data sort as "numbers", for example, if I have records these:

Date
24/09/2008
15/10/2008
02/10/2008
13/10/2008
10/10/2008
15/09/2008

After clic the column header I got this:

Date
02/10/2008
03/10/2008
10/10/2008
15/10/2008
15/09/2008
24/10/2008

My system date format is (Day/Month/Year), that's why the dates are in that format.

If I click again the order is 24, 15,15,10,03,02

In the Rowpopulating event I have this:

e.Values(6).DisplayValue = bo.FechaEnvio.ToShortDateString

The sorting is only counting the first digits (the day in my case), Is there a way to fix this, to sort correctly for the complete date?

Kindest regards

Smile Everything is possible, just keep trying...

Replies
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Juan,

Try this as it worked for me and did not require any change to the framework.  I set the column initial column sort index to the date column and it sorted as it should first thing:

So set the DefaultSortColumn = 2 and it should work correctly.

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
OK...I found the problem.  It will require a change.  The column sorter evaluates the column type once and then attempts to sort using that type for all other columns.  So if the date is your default column, it will sort dates correctly and not the string and vice versa.  I will fix this now and it will be in the next beta posted.

Thanks for the sample!

Juan Carlos Pazos
Juan Carlos Pazos
StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)
Group: Forum Members
Posts: 144, Visits: 227
Trent

Thanks for your support and the time invested. I will wait for the next update.

Kindest regards

Smile Everything is possible, just keep trying...

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I might make the suggestion that you expose the ListViewSorter. That way, if there is some issue with the default provided (or some weird sorting needed), an alternative can easily be provided.
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Actually, it already is.  The ListView has a Sorter property that allows you to attach any sorter that you would like.  We just happen to attach the ListViewColumnSorter class by default.  But you can create your own as this is a function of the ListView control.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
OK, I just took a look at the source and I need to be more specific. I know that I can use my own sorter with the listview and have done that (thanks to some previous help!). However, I was thinking that it'd be nice if I could provide my own sorter and get the nice auto sorting on column clicks etc. In order to get that currently, I need to provide not only the sorter, but also the code to handle column clicks, swap order on columns etc. (not a huge deal...but always looking to leverage the framework).



I see that this would actually a bit more work by you, as you not only have to expose the sorter, but also either use a base class or interface, so this would work. I still think this would be nice, but as you get your sorter worked out, there might be less of a need for what I'm asking.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Juan Carlos Pazos - 17 Years Ago
Trent L. Taylor - 17 Years Ago
Juan Carlos Pazos - 16 Years Ago
Trent L. Taylor - 16 Years Ago
Juan Carlos Pazos - 16 Years Ago
                         Juan, Try this as it worked for me and did not require any change to...
Trent L. Taylor - 16 Years Ago
                             OK...I found the problem. It will require a change. The column sorter...
Trent L. Taylor - 16 Years Ago
                                 Trent Thanks for your support and the time invested. I will wait for...
Juan Carlos Pazos - 16 Years Ago
                                     I might make the suggestion that you expose the ListViewSorter. That...
Greg McGuffey - 16 Years Ago
                                         Actually,it already is. The ListView has a Sorter property that allows...
Trent L. Taylor - 16 Years Ago
                                             OK, I just took a look at the source and I need to be more specific....
Greg McGuffey - 16 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search