ListView - ColClick: Sort up / sort down

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

ListView - ColClick: Sort up / sort down

07 Mar 2016, 05:32

Already done:
To click on a column header toggles the sorting of a column "up / down" (asc. / desc.).
With "Colclick" I can remember the number of the sorted column.

Question:
How to recognize, store and reuse if the column was sorted "up or down"?
Is there a built in feature or must it be handled with subroutines, counters and so on?

Peter
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
wizardzedd
Posts: 319
Joined: 23 Jan 2016, 23:03

Re: ListView - ColClick: Sort up / sort down

07 Mar 2016, 15:37

Code: Select all

gui, Add, ListView, gLVClick, A|B|C
LV_Add("", 1, 2, 3)
LV_Add("", 4, 5, 6)
LV_Add("", 7, 8, 9)
gui, Show
return
LVClick:
if(A_GuiEvent = "ColClick") {
	LV_GetText(Out1, 1, A_EventInfo)
	LV_GetText(Out2, 2, A_EventInfo)
	isSortedDown:=Out2 > Out1
	MsgBox % isSortedDown ? "Sorted down!" : "Sorted Up!"
}
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Re: ListView - ColClick: Sort up / sort down

07 Mar 2016, 16:25

Thanks - fine and compact!
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
wizardzedd
Posts: 319
Joined: 23 Jan 2016, 23:03

Re: ListView - ColClick: Sort up / sort down

07 Mar 2016, 16:55

Of course there is a flaw if you have the same value...

Code: Select all

gui, Add, ListView, gLVClick, A|B|C
LV_Add("", 1, 2, 3)
LV_Add("", 1, 8, 6)
LV_Add("", 7, 8, 9)
gui, Show
return
LVClick:
if(A_GuiEvent = "ColClick") {
	LV_GetText(Out1, 1, A_EventInfo)
	LV_GetText(Out2, 2, A_EventInfo)
	while(Out1 = Out2)
		LV_GetText(Out2, A_Index + 2, A_EventInfo)
	isSortedDown:=Out2 > Out1
	MsgBox % isSortedDown ? "Sorted down!" : "Sorted Up!"
}
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Re: ListView - ColClick: Sort up / sort down

07 Mar 2016, 17:12

I modified it to check first against last value, and change the operator:

Code: Select all

        LV_GetText(Out1, 1, A_EventInfo)
        LV_GetText(Out2, LV_GetCount(), A_EventInfo)
        isSortedDown := Out2 < Out1
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww and 130 guests