Jump to content

ListView sorting on date


ahha
 Share

Go to solution Solved by ahha,

Recommended Posts

Newbie to _GUICtrlListView_RegisterSortCallBack and can't get it to sort properly on date in format MM/DD/YYYY.

Example code below.  Q - How do I get the date to sort properly?

;#AutoIt3Wrapper_run_debug_mode=Y
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Global $g_id_ListView

Example()
Exit

Func Example()
    Local $idRow1, $idRow2, $idRow3
    GUICreate("ListView Sort Question", 300, 200)
    $g_id_ListView = GUICtrlCreateListView("Row#|Name|Date", 10, 10, 280, 180)
    $id_Row1 = GUICtrlCreateListViewItem("#1|Alice|01/15/2022", $g_id_ListView)
    $id_Row2 = GUICtrlCreateListViewItem("#2|Bob|02/22/2021", $g_id_ListView)
    $id_Row3 = GUICtrlCreateListViewItem("#3|Carol|03/13/2021", $g_id_ListView)
    $id_Row10 = GUICtrlCreateListViewItem("#10|Dave|10/09/2021", $g_id_ListView)
    $id_Row11 = GUICtrlCreateListViewItem("#11|Eve|11/21/2021", $g_id_ListView)

    GUISetState(@SW_SHOW)
    ;$vCompareType = 0  ;not ok as Row# sort #1, #10, and want #1, #2,
    ;$vCompareType = 1  ;not ok as Row# sort #1, #10, and want #1, #2,
    $vCompareType = 2   ;Row# okay but Date messed up
    _GUICtrlListView_RegisterSortCallBack($g_id_ListView, $vCompareType)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $g_id_ListView
                ;MsgBox(0,"","col="&GUICtrlGetState($g_id_ListView))
                _GUICtrlListView_SortItems($g_id_ListView, GUICtrlGetState($g_id_ListView))
        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($g_id_ListView)
    GUIDelete($g_id_ListView)
EndFunc   ;Func Example()

 

Link to comment
Share on other sites

Luke94,

Thanks.  Working through it but at this point pretty confused.  Yikes DLLs I am at a loss. 

In Example 1 of GUICtrlRegisterListViewSort where does $LVM_SETSELECTEDCOLUMN come from in this code?

GUICtrlSendMsg($idLv, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($idLv), 0)

Also does LVSort routine just pull out and sort on $iColumn = 2?  That is, how are the other columns sorted?  Do they go to some other routine?

I ask because DllStructSetData scares the heck out of me as I don't know what the structure is and what's required or what it does.

I guess a main question is if I sort on a particular column are all the other columns pulled along and sorted as well?

For example:

              Col 0 | Col1 | Col 2

Row 0  R0C0   R0C1    R0C2

Row 1  R1C0   R1C1    R1C2

Row 2  R2C0   R2C1    R2C2

If I sort on Col 1 are the Rows associated with each Column automatically also pulled along?  Or do the other row entries stay fixed and only the items in the selected column sorted?  I ask this because in Example 1 I don't understand how $iResult works or this code below works, because I don't see where things get switched around or sorted.

; Switch the sorting direction
    If $iColumn = $g_iCurCol Then
        If Not $g_bSet Then
            $g_iSortDir = $g_iSortDir * -1
            $g_bSet = True
        EndIf
    Else
        $g_iSortDir = 1
    EndIf

Any answers appreciated.

Link to comment
Share on other sites

A simpler way using a workaround : create a col #3 (width=0)  for sorting only

;#AutoIt3Wrapper_run_debug_mode=Y
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#Include <Array.au3>

Global $g_id_ListView

Example()
Exit

Func Example()
    Local $array[5] = [ _ 
    "#1|Alice|01/15/2022", _ 
    "#2|Bob|02/22/2021", _ 
    "#3|Carol|03/13/2021", _ 
    "#10|Dave|10/09/2021", _ 
    "#11|Eve|11/21/2021"]
; _ArrayDisplay($array)

   GUICreate("ListView Sort Question", 300, 200)
   $g_id_ListView = GUICtrlCreateListView("Row#|Name|Date| ", 10, 10, 280, 180)
   For $i = 0 to UBound($array)-1
    GUICtrlCreateListViewItem($array[$i] & "|" & StringRegExpReplace($array[$i], '.*(\d{2})/(\d{2})/(\d{4})', "$3$1$2"), $g_id_ListView)
   Next
   _GUICtrlListView_SetColumnWidth($g_id_ListView, 3, 0)
   GUISetState(@SW_SHOW)
   _GUICtrlListView_RegisterSortCallBack($g_id_ListView)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $g_id_ListView
                ;MsgBox(0,"","col="&GUICtrlGetState($g_id_ListView))
            ; If col 2 is clicked then use col 3 for sorting <<<<<<<<<<<<<<<<<<<<<<
                If GUICtrlGetState($g_id_ListView) = 2 Then _GUICtrlListView_SortItems($g_id_ListView, 3)
        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($g_id_ListView)
    GUIDelete($g_id_ListView)
EndFunc   ;Func Example()

 

Link to comment
Share on other sites

1 hour ago, Nine said:

@mikell Nice idea.  Only problem is that the arrow (up/down) will be misplaced.

Hi everybody,
I just tried a way to get the sort arrow appear on any column.

179178734_forcearrowindesiredcolumn.png.e334d33d357be79c22aeb6e788ec6801.png

* Left pic shows what we got actually : click on col 2, sort on col 3, arrow displays on col 3 (this col 3 is correctly hidden in the real script, but let's show it in the pics for convenience)

* Right pic shows a way to display it differently : click on col 2, sort on col 3, arrow forced on col 2

To do this, I added a 3rd optional parameter in the called function :

Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)

And replaced $iCol by $iCol_Arrow 3 times in this part of the called function :

$iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol_Arrow)
If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
    _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTUP))
Else ; descending
    _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTDOWN))
EndIf

Then in mikell's script, the function is called including the 3rd parameter, forcing the arrow to be displayed on column 2 :

If GUICtrlGetState($g_id_ListView) = 2 Then _GUICtrlListView_SortItems($g_id_ListView, 3, 2)

Quickly tested, but if a user isn't confident in reworking an include file, please be careful (always make a copy of the original include file first +++)

Edited by pixelsearch
Link to comment
Share on other sites

@pixelsearch

So if I understand correctly you changed in the include file GuiListView.au3

This:

; #FUNCTION# ====================================================================================================================
; Author ........: Gary Frost (gafrost)
; Modified.......:
; ===============================================================================================================================
Func _GUICtrlListView_SortItems($hWnd, $iCol)
    Local $iRet, $iIndex, $pFunction, $hHeader, $iFormat

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    For $x = 1 To $__g_aListViewSortInfo[0][0]
        If $hWnd = $__g_aListViewSortInfo[$x][1] Then
            $iIndex = $x
            ExitLoop
        EndIf
    Next

    $pFunction = DllCallbackGetPtr($__g_aListViewSortInfo[$iIndex][2]) ; get pointer to call back
    $__g_aListViewSortInfo[$iIndex][3] = $iCol ; $nColumn = column clicked
    $__g_aListViewSortInfo[$iIndex][7] = 0 ; $bSet
    $__g_aListViewSortInfo[$iIndex][4] = $__g_aListViewSortInfo[$iIndex][6] ; nCurCol = $nCol
    $iRet = _SendMessage($hWnd, $LVM_SORTITEMSEX, $hWnd, $pFunction, 0, "hwnd", "ptr")
    If $iRet <> 0 Then
        If $__g_aListViewSortInfo[$iIndex][9] Then ; Use arrow in header
            $hHeader = $__g_aListViewSortInfo[$iIndex][10]
            For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
                $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $x)
                If BitAND($iFormat, $HDF_SORTDOWN) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTDOWN))
                ElseIf BitAND($iFormat, $HDF_SORTUP) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTUP))
                EndIf
            Next
            $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol)
            If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTUP))
            Else ; descending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTDOWN))
            EndIf
        EndIf
    EndIf

    Return $iRet <> 0
EndFunc   ;==>_GUICtrlListView_SortItems

to this?

; #FUNCTION# ====================================================================================================================
; Author ........: Gary Frost (gafrost)
; Modified.......:
; ===============================================================================================================================
Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)
    Local $iRet, $iIndex, $pFunction, $hHeader, $iFormat

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    For $x = 1 To $__g_aListViewSortInfo[0][0]
        If $hWnd = $__g_aListViewSortInfo[$x][1] Then
            $iIndex = $x
            ExitLoop
        EndIf
    Next

    $pFunction = DllCallbackGetPtr($__g_aListViewSortInfo[$iIndex][2]) ; get pointer to call back
    $__g_aListViewSortInfo[$iIndex][3] = $iCol ; $nColumn = column clicked
    $__g_aListViewSortInfo[$iIndex][7] = 0 ; $bSet
    $__g_aListViewSortInfo[$iIndex][4] = $__g_aListViewSortInfo[$iIndex][6] ; nCurCol = $nCol
    $iRet = _SendMessage($hWnd, $LVM_SORTITEMSEX, $hWnd, $pFunction, 0, "hwnd", "ptr")
    If $iRet <> 0 Then
        If $__g_aListViewSortInfo[$iIndex][9] Then ; Use arrow in header
            $hHeader = $__g_aListViewSortInfo[$iIndex][10]
            For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
                $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol_Arrow)
                If BitAND($iFormat, $HDF_SORTDOWN) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitXOR($iFormat, $HDF_SORTDOWN))
                ElseIf BitAND($iFormat, $HDF_SORTUP) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitXOR($iFormat, $HDF_SORTUP))
                EndIf
            Next
            $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol)
            If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTUP))
            Else ; descending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTDOWN))
            EndIf
        EndIf
    EndIf

    Return $iRet <> 0
EndFunc   ;==>_GUICtrlListView_SortItems

Several questions.

1) I was not aware you could assign in a function call like this

Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)

Are the parameters evaluated in order?  Or if the 3rd parameter is passed it overwrites the equation?

2) For the original code: For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1

What happened to x?  That is, I do not see it being used anymore in the modified version of Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)?

 

Link to comment
Share on other sites

1 hour ago, ahha said:

Are the parameters evaluated in order?

Yes there are . A couple of examples show it :

f(1, 2)

Func f($p1, $p2, $p3 = $p2)
    ConsoleWrite($p3 & @lf) ; displays 2
EndFunc

========================================
f(1, 2, 3)

Func f($p1, $p2, $p3 = $p2)
    ConsoleWrite($p3 & @lf) ; displays 3
EndFunc

========================================
; What follows displays an error :
; "Variable used without being declared"

f(1, 2)

Func f($p1, $p2, $p3 = $p4, $p4 = 4) ; error
    ConsoleWrite($p3 & @lf)
EndFunc

 

1 hour ago, ahha said:

Or if the 3rd parameter is passed it overwrites the equation?

Yes it does as it's an optional parameter.  Optional parameters are placed at the end of the function definition, after the regular parameters.

 

1 hour ago, ahha said:

For the original code: For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1

What happened to x?  That is, I do not see it being used anymore in the modified version of Func

Well... i don't see it used in the original function, after it ended its job :

For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
    ...
Next

This loop is used to make disappear an eventual sort arrow (asc or desc) placed in any column of the listview. When the loop has ended, then $x isn't found anymore in the original function. Same for the reworked function, where the 3 lines patched have nothing to do with $x

Hope it helps :)

Link to comment
Share on other sites

@ahha: you patched the wrong lines in your post. Please look at my initial post to make sure what 3 lines need to be patched (they're placed outside the For $x loop, not inside). I'll paste the whole patched function below so it will be clearer :

; #FUNCTION# ==================================================
; Author ........: Gary Frost (gafrost)
; Modified.......: pixelsearch (added a 3rd optional parameter)
; =============================================================

Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)
    Local $iRet, $iIndex, $pFunction, $hHeader, $iFormat

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    For $x = 1 To $__g_aListViewSortInfo[0][0]
        If $hWnd = $__g_aListViewSortInfo[$x][1] Then
            $iIndex = $x
            ExitLoop
        EndIf
    Next

    $pFunction = DllCallbackGetPtr($__g_aListViewSortInfo[$iIndex][2]) ; get pointer to call back
    $__g_aListViewSortInfo[$iIndex][3] = $iCol ; $nColumn = column clicked
    $__g_aListViewSortInfo[$iIndex][7] = 0 ; $bSet
    $__g_aListViewSortInfo[$iIndex][4] = $__g_aListViewSortInfo[$iIndex][6] ; nCurCol = $nCol
    $iRet = _SendMessage($hWnd, $LVM_SORTITEMSEX, $hWnd, $pFunction, 0, "hwnd", "ptr")
    If $iRet <> 0 Then
        If $__g_aListViewSortInfo[$iIndex][9] Then ; Use arrow in header
            $hHeader = $__g_aListViewSortInfo[$iIndex][10]
            For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
                $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $x)
                If BitAND($iFormat, $HDF_SORTDOWN) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTDOWN))
                ElseIf BitAND($iFormat, $HDF_SORTUP) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTUP))
                EndIf
            Next
            $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol_Arrow)
            If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTUP))
            Else ; descending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTDOWN))
            EndIf
        EndIf
    EndIf

    Return $iRet <> 0
EndFunc   ;==>_GUICtrlListView_SortItems

 

Edited by pixelsearch
Link to comment
Share on other sites

  • Solution

Thanks to all for the answers/suggestions.  They provided me lots of information and I learned much. 

Here's my version that does not need to use GUICtrlRegisterListViewSort (thanks @Luke94), does not need a phantom column (thanks @mikell), and takes care of the up/down arrow issue (thanks @pixelsearch).

I basically use an array to load listview with MM/DD/YYYY format, then when header is clicked I alter array to YYYYMMDD format, load it back into listview, let listview use the regular sort, then load listview back to the array, convert array back to MM/DD/YYYY format and reload listview.

I know a lot of loads/reloads but it's straightforward and I understand it (excuse all the debug statements, it helps me :). 

Any comments welcomed.

#AutoIt3Wrapper_run_debug_mode=Y
#include <Debug.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
AutoItSetOption("MustDeclareVars", 1)
;v1a - original
;v1b - creating array that we can array->listview, and listview->array
;v1c - changing $aListView because using _GUICtrlListView_AddArray
;v1d - try using all UDF _ functions as mixing could cause issues
;v1e - cleaning out extraneous code
;v1f - released

Global $debug = 0, $g_h_GUI, $g_id_ListView

Example()
Exit

Func Example()
    Local $idRow1, $idRow2, $idRow3, $i, $j, $iRow, $jCol, $string, $aTemp
    $g_h_GUI = GUICreate("ListView Sort Question", 300, 200)    ;get handle in case we need it later
    ;$g_id_ListView = _GUICtrlListView_Create($g_h_GUI, "Row#|Name|Date       ", 10, 10, 280, 180)  ;v1d
    $g_id_ListView = GUICtrlCreateListView("Row#|Name|Date       ", 10, 10, 280, 180)

    ;v1c
    $iRow = 5
    $jCol = 3
    Local $aListView[$iRow][$jCol] = _
    [ _
    ["#1","Alice","01/15/2022"] , _
    ["#2","Bob","02/22/2021"] , _
    ["#3","Carol","03/13/2021"] , _
    ["#10","Dave","10/09/2021"] , _
    ["#11","Eve","11/21/2021"] _
    ]

    ;_DebugArrayDisplay($aListView)
    _GUICtrlListView_AddArray($g_id_ListView, $aListView)   ;load listview

    GUISetState(@SW_SHOW)
    ;$vCompareType = 0  ;not ok as Row# sort #1, #10, and want #1, #2,
    ;$vCompareType = 1  ;not ok as Row# sort #1, #10, and want #1, #2,
    Local $vCompareType = 2 ;Row# okay but Date messed up
    _GUICtrlListView_RegisterSortCallBack($g_id_ListView, $vCompareType)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $g_id_ListView
                ;Pause("col="&GUICtrlGetState($g_id_ListView))
                If GUICtrlGetState($g_id_ListView) = 2 Then     ;date column so we do a special sort
                    For $i = 0 to $iRow - 1     ;overwrite in array col MM/DD/YYYY with YYYYMMDD for sorting purposes
                        $string = $aListView[$i][2] ;initially MM/DD/YYYY format
                        $string = StringRight($string, 4) & StringLeft($string, 2) & StringMid($string, 4, 2)       ;now in YYYYMMDD format
                        $aListView[$i][2] = $string ;stuff into array
                    Next
                    If $debug <> 0 Then _DebugArrayDisplay($aListView, "$aListView after converting to YYYYMMDD format")
                    _GUICtrlListView_DeleteAllItems($g_id_ListView) ;clear out listview
                    Pause("Listview cleared")
                    _GUICtrlListView_AddArray($g_id_ListView, $aListView)   ;reload listview from array
                    Pause("Listview reloaded with YYYYMMDD date format")
                    _GUICtrlListView_SortItems($g_id_ListView, GUICtrlGetState($g_id_ListView)) ;use standard sort
                    Pause("Standard sort used on YYYYMMDD date format")

                    For $i = 0 to $iRow - 1     ;get each row of listview into array
                        $aTemp = _GUICtrlListView_GetItemTextArray($g_id_ListView, $i)      ;get row $i into $aTemp [0] has count
                        For $j = 1 to $aTemp[0]
                            $aListView[$i][$j - 1] = $aTemp[$j]     ;stick it back into $aListView
                        Next
                    Next
                    If $debug <> 0 Then _DebugArrayDisplay($aListView, "After loop: $aListView after reading $g_id_ListView")
                    ;now convert YYYYMMDD in array to MM/DD/YYYY format then load array into listview
                    For $i = 0 to $iRow - 1     ;overwrite in array col YYYYMMDD with MM/DD/YYYY
                        $string = $aListView[$i][2] ;YYYYMMDD format
                        $string = StringMid($string, 5, 2) &"/"& StringRight($string, 2) &"/"& StringLeft($string, 4)   ;now in MM/DD/YYYY format
                        $aListView[$i][2] = $string ;stuff into array
                    Next
                    If $debug <> 0 Then _DebugArrayDisplay($aListView, "$aListView after YYYYMMDD to MM/DD/YYYY")
                    ;now stuff back into listview
                    _GUICtrlListView_DeleteAllItems($g_id_ListView) ;clear out listview
                    _GUICtrlListView_AddArray($g_id_ListView, $aListView)   ;reload listview from array
                    Pause("Listview reloaded with MM/DD/YYYY date format")

                Else
                    ;use standard sort
                    _GUICtrlListView_SortItems($g_id_ListView, GUICtrlGetState($g_id_ListView)) ;use standard sort
                EndIf

        EndSwitch
    WEnd


    _GUICtrlListView_UnRegisterSortCallBack($g_id_ListView)
    GUIDelete($g_id_ListView)
EndFunc   ;Func Example()

Func  Pause($text="")
    If $debug <> 0 Then MsgBox(262144, "DEBUG", "Paused: " & $text)
EndFunc

 

 

Link to comment
Share on other sites

  • 1 year later...
On 1/18/2022 at 10:55 PM, pixelsearch said:

@ahha: you patched the wrong lines in your post. Please look at my initial post to make sure what 3 lines need to be patched (they're placed outside the For $x loop, not inside). I'll paste the whole patched function below so it will be clearer :

; #FUNCTION# ==================================================
; Author ........: Gary Frost (gafrost)
; Modified.......: pixelsearch (added a 3rd optional parameter)
; =============================================================

Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)
    Local $iRet, $iIndex, $pFunction, $hHeader, $iFormat

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    For $x = 1 To $__g_aListViewSortInfo[0][0]
        If $hWnd = $__g_aListViewSortInfo[$x][1] Then
            $iIndex = $x
            ExitLoop
        EndIf
    Next

    $pFunction = DllCallbackGetPtr($__g_aListViewSortInfo[$iIndex][2]) ; get pointer to call back
    $__g_aListViewSortInfo[$iIndex][3] = $iCol ; $nColumn = column clicked
    $__g_aListViewSortInfo[$iIndex][7] = 0 ; $bSet
    $__g_aListViewSortInfo[$iIndex][4] = $__g_aListViewSortInfo[$iIndex][6] ; nCurCol = $nCol
    $iRet = _SendMessage($hWnd, $LVM_SORTITEMSEX, $hWnd, $pFunction, 0, "hwnd", "ptr")
    If $iRet <> 0 Then
        If $__g_aListViewSortInfo[$iIndex][9] Then ; Use arrow in header
            $hHeader = $__g_aListViewSortInfo[$iIndex][10]
            For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
                $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $x)
                If BitAND($iFormat, $HDF_SORTDOWN) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTDOWN))
                ElseIf BitAND($iFormat, $HDF_SORTUP) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTUP))
                EndIf
            Next
            $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol_Arrow)
            If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTUP))
            Else ; descending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTDOWN))
            EndIf
        EndIf
    EndIf

    Return $iRet <> 0
EndFunc   ;==>_GUICtrlListView_SortItems

 

Thanks for the info @pixelsearch.  I need to do something similar and would have eventually gotten there by myself, but you saved me a lot of work.  Much appreciated!

If you haven't already done so, I suggest you submit the change for inclusion in the next Autoit release.

Edited by BrunoJ
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...