Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Listview sorting dates (2002/SP2)

    I have been unsuccessful in my attempts at sorting dates in a listview control. After some research I have found that the listview converts all fields to a string. Is this correct? Now to my question...Is there an easy way to sort a general date (4/18/05 12:35 PM) correctly in a listview?

    Thanks,
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Listview sorting dates (2002/SP2)

    Create an extra column in the listview control, and hide it by setting its column width to 0. Populate this column with the dates formatted as yyyymmdd hh:mm, ie. using
    Format([Datefield], "yyyymmdd hh:mm")
    You can sort on this hidden column. Because of the formatting, the sort order will be chronological.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listview sorting dates (2002/SP2)

    Sounds good to me! My column headers are sortable. How would I sort the hidden column when the visible date column header is clicked?

    Thanks,
    Don

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Listview sorting dates (2002/SP2)

    In the ColumnClick event handler, set the SortKey property to the index of the hidden column instead of to the index of the display column.

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listview sorting dates (2002/SP2)

    Works beautifully!! Thanks again!

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listview sorting dates (2002/SP2)

    Hans,

    The sorting when clicking a column header is working great but when I initially open the form and fill the
    listview with the select statement the Order By (Date DESC) seems to be working because the item that would
    be first is selected but it isn't at the top. It is somewhere in the middle. When I click on the date column header
    It is visually sorted properly but in ASC by Date. I then click the date column header again and it visually sorts
    the date column properly in DESC.

    Do you know what I'm doing wrong here?

    Thanks,
    Don

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Listview sorting dates (2002/SP2)

    I don't know what causes this, but you could call the column header click code to sort the list box after it has been populated.

  8. #8
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listview sorting dates (2002/SP2)

    OK, so I take it that this is a known bug. I just didn't want to jump through another hoop because of a bug if it was actually something I was doing wrong!

    Thanks Hans!

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Listview sorting dates (2002/SP2)

    I don't know much about the listview control, so I can't tell you if it's a known bug. But sorting the listview explicitly is probably less trouble than spending a lot of time trying to find out why it isn't sorted correctly originally.

Posting Permissions

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