Results 1 to 4 of 4

Thread: Sorting a Listview by a Column?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    Brisbane, Qld, Australia
    Posts
    78
    Hi,

    I have a column in my listview that I want have sorted. At present I have the listview sorted and in descending order. The field that I have loaded from the database is a DATE field. My problem is : The listview sorts the data but by the first number of the date field. Is there a way to make it sort the whole date and have it sort in descending order and not just the first 2 numbers of the date. Any ideas would be greatly appreciated and Thanks in advance.

    Mike

  2. #2
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    Try this:

    Convert Dates to YYYYMMDD format
    ListView.Sorted = True
    ListView.Sorted = False
    Convert Dates back to usual format

    I store the type of column in the Listview column Tag at population, so that I know what type the column is when I sort.
    By the way, the General VB forum is the best place to get VB questions answered.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    Brisbane, Qld, Australia
    Posts
    78
    Hi,

    I am not sure what you mean to convert the date to YYYYMMDD. I mean where do you mean to change it. do you mean in the database or in the listview as it loads or where? Not sure.

    Also not usre what you mean by the .tag property either, well how to use it anyway.


    Mike

  4. #4
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    The code goes in the ColumnClick event of the Listview.
    You know which column you're in by the Index property passed into the event.

    This is code to convert the 1st column to the sort format:

    For i = 1 To ListView.ListItems.Count
    ListView.ListItems(i).Text = Format(ListView.ListItem(i).Text, "yyyymmdd")
    Next i

    You'll have to write a function to convert back to the display format following the sort.

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