CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Sorting.

  1. #1
    Join Date
    Oct 1999
    Posts
    7

    Sorting.

    Hi, how do I sort by date (not the alphabetical value of it!!) a listview control?? Thanks.


  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Sorting.

    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

  3. #3
    Join Date
    Oct 1999
    Posts
    7

    Re: Sorting.

    Will it work in comparisons like 00/01/01 - 99/12/31?? I don't think so...


  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Sorting.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured