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