You should not unregister/register the sort function after every sort. Only when you sort by another column. This is the code in post 2:
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StructureConstants.au3>
Opt('MustDeclareVars', 1)
Global $search_LV, $B_DESCENDING
GUICreate("ListView Sort by Column Click", 400, 300)
$search_LV = GUICtrlCreateListView("String|Number|String", 2, 2, 394, 268)
GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("line4|5|1A", $search_LV)
GUICtrlCreateListViewItem("line5|4.50 |1B", $search_LV)
GUICtrlCreateListViewItem("line5|4.0 |2C", $search_LV)
GUICtrlCreateListViewItem("line3|23|01", $search_LV)
GUICtrlCreateListViewItem("line2|0.34560 |09", $search_LV)
GUICtrlCreateListViewItem("line1|1.0 |7A", $search_LV)
GUICtrlCreateListViewItem("line1|0.1 |8C", $search_LV)
GUICtrlCreateListViewItem("line1|97|5B", $search_LV)
GUICtrlCreateListViewItem("line1|910|9B", $search_LV)
GUICtrlCreateListViewItem("line1|99|11", $search_LV)
GUICtrlCreateListViewItem("line1|990.99|06", $search_LV)
_GUICtrlListView_SetColumnWidth($search_LV, 0, 75)
_GUICtrlListView_SetColumnWidth($search_LV, 1, 75)
_GUICtrlListView_SetColumnWidth($search_LV, 2, 75)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
;~ _GUICtrlListView_RegisterSortCallBack($search_LV, False)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $search_LV
; Kick off the sort callback
;~ _GUICtrlListView_SortItems($search_LV, GUICtrlGetState($search_LV))
;~ _GUICtrlListView_UnRegisterSortCallBack($search_LV)
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local Static $ColumnSortedPrev = -1
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $search_LV
;~ If Not IsHWnd($search_LV) Then $hWndListView = GUICtrlGetHandle($search_LV)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
;~ Case $search_LV
Case GUICtrlGetHandle($search_LV)
Switch $iCode
Case $LVN_COLUMNCLICK ; A column was clicked
ConsoleWrite("Header geklickt" & @CRLF)
Local $tInfo = DllStructCreate($tagNMLISTVIEW, $iLparam)
Local $ColumnSorted = DllStructGetData($tInfo, 'SubItem')
If $ColumnSortedPrev <> $ColumnSorted Then
If $ColumnSortedPrev > -1 Then _GUICtrlListView_UnRegisterSortCallBack($search_LV)
If $ColumnSorted = 1 Then
ConsoleWrite('Numeric: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, True) & @CRLF)
Else
ConsoleWrite('Literal: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, False) & @CRLF)
EndIf
$ColumnSortedPrev = $ColumnSorted
EndIf
_GUICtrlListView_SortItems($search_LV, DllStructGetData($tInfo, 'SubItem'))
EndSwitch
EndSwitch
EndFunc ;==>WM_NOTIFY