Page 1 of 1

ListView - ColClick: Sort up / sort down

Posted: 07 Mar 2016, 05:32
by Peter2
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

Re: ListView - ColClick: Sort up / sort down

Posted: 07 Mar 2016, 15:37
by wizardzedd

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!"
}

Re: ListView - ColClick: Sort up / sort down

Posted: 07 Mar 2016, 16:25
by Peter2
Thanks - fine and compact!

Re: ListView - ColClick: Sort up / sort down

Posted: 07 Mar 2016, 16:55
by wizardzedd
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!"
}

Re: ListView - ColClick: Sort up / sort down

Posted: 07 Mar 2016, 17:12
by Peter2
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

Re: ListView - ColClick: Sort up / sort down

Posted: 07 Mar 2016, 17:22
by wizardzedd
That is better :)