Hi, how do I sort by date (not the alphabetical value of it!!) a listview control?? Thanks.
Printable View
Hi, how do I sort by date (not the alphabetical value of it!!) a listview control?? Thanks.
I have seen some code, if i am not mistaken on Mart Hart's site.( Sorry if i spelt the name wrong!)
--
One trick you can try is: add an extra column which is not visible and add the date entries all formated with "yy/mm/dd". then set the SortKey value to this coluumn id. this format is imp. because "99/3/11" > "99/03/11" in string comparision.
RK
Will it work in comparisons like 00/01/01 - 99/12/31?? I don't think so...
The method of sorting a date in YYYY/MM/DD format as a string will work - you're in very dodgy territory if you start comparing dates and using a 2 digit year - you will have to write your own century handling code that way.
Why not do the following :
1. Display your data in the listview, make sure that dates are displayed in the relevant format for the county (eg. dd/mm or mm/dd) - but ensure that they have a four-digit year displayed. (see http://codeguru.developer.com/vb/articles/1716.shtml for help with international settings)
2. when you sort, do as Ravi suggested (eg. add an extra column with width=0, copy dates into yyyy/mm/dd format, then sort normally as a string, then remove that column)
- it's a whole lot easier than writing call-back routines with the listview for custom sorting (and probably quicker too).
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb