Reverse Sort Listview?

Get help with using AutoHotkey and its commands and hotkeys
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Reverse Sort Listview?

31 Oct 2020, 02:54

Hi everyone

I'm using this line in my code, and it sorts the listview alphabetically - but this isn't what I'm looking to do.

What do I have to change here in order to sort the listview in reverse-order? (bottom line of listview will appear at top).. I can't find the proper info or syntax in the documentation...

Thanks in advance :)
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Reverse Sort Listview?

31 Oct 2020, 02:55

oops, it might help if I actually included that line of code (d'oh!)...

LV_ModifyCol(1,"Sort")
User avatar
Jim Dunn
Posts: 360
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: Reverse Sort Listview?

31 Oct 2020, 03:13

Does

Code: Select all

 LV_ModifyCol(ColumnNumber, "SortDesc")
work?

from: https://www.autohotkey.com/docs/commands/ListView.htm#Column_Options_Sorting
Sort: Immediately sorts the column in ascending order (even if it has the Desc option).

SortDesc: Immediately sorts the column in descending order.
There's also:
Desc: Descending order. The column starts off in descending order the first time the user sorts it.
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Reverse Sort Listview?

31 Oct 2020, 13:07

thanks Jim!

whoops, edit - "SortDesc" just alphabetially reverses the list, so Z would be at the top of the list.

I was hoping to first load in the listview (which is loaded from a randomly-sorted, non-alphabeticalized text file), and then when the list is loaded, just reverse its order so the bottom item appears at the top, and so on.

Maybe when reading from the text file, it should somehow read from the bottom up (instead of top down) in order for this to work?
scriptor2016
Posts: 710
Joined: 21 Dec 2015, 02:34

Re: Reverse Sort Listview?

31 Oct 2020, 17:26

After searching the forums, a workable approach is indeed to reverse-read the text file in order to have the bottom line appear at the top of the listview:

Code: Select all

targetFile = C:\MyFile.txt
lineCount :=
Loop,
    {
    FileReadLine, nullVar, %targetFile%, %A_Index%
     if ErrorLevel
            break
    lineCount := A_Index
    }
Loop,
    {
    FileReadLine, currentLine, %targetFile%, %lineCount%
     if ErrorLevel
         {
         break
         }
    lineCount--
    msgbox, %currentLine%
    }
User avatar
kczx3
Posts: 1223
Joined: 06 Oct 2015, 21:39

Re: Reverse Sort Listview?

31 Oct 2020, 19:38

Don’t reverse read the file. I would just read the file, split it on `n, then reverse loop the resulting array to populate the list view.

Return to “Ask For Help”

Who is online

Users browsing this forum: alexsu, Bing [Bot], boiler, Google [Bot], mikeyww and 44 guests