PartyPooper Posted November 29, 2009 Posted November 29, 2009 Can someone tell me why the following sort fails (well, half fails - it only sorts in one direction)? expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ; 1 = enable. Opt("GUICloseOnESC", 1) ; 1 = Send the $GUI_EVENT_CLOSE message when ESC is pressed (default). Opt('MustDeclareVars', 1) Global $hListView, $hListView2 _Example1() While 1 Sleep(3000) WEnd Func _Example1() Local $hImage, $aIcons[3] = [0, 3, 6] Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER) GUICreate("ListView Sort", 300, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI") $hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180, -1, $iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle) GUICtrlSetOnEvent($hListView, "sort") ; Load images $hImage = _GUIImageList_Create(18, 18, 5, 3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -7) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -12) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -4) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -5) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -6) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -9) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -10) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -11) _GUICtrlListView_SetImageList($hListView, $hImage, 1) _AddRow($hListView, "ABC|000666|10.05.2004", $aIcons) _AddRow($hListView, "DEF|444|11.05.2005", $aIcons, 1) _AddRow($hListView, "CDE|555|12.05.2004", $aIcons, 2) GUISetState() EndFunc ;==>_Example1 Func sort() _GUICtrlListView_RegisterSortCallBack($hListView) _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView)) _GUICtrlListView_UnRegisterSortCallBack($hListView) EndFunc ;==>sort Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0) Local $aItem = StringSplit($sItem, "|") Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 9999) _GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER) For $x = 2 To $aItem[0] _GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus) _GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE) Next EndFunc ;==>_AddRow Func CloseGUI() GUIDelete() Exit EndFunc ;==>CloseGUI
picaxe Posted November 30, 2009 Posted November 30, 2009 Registering and unregistering sort callback in sort() means the previous sort direction can not be recalled in subsequent calls to sort. expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ; 1 = enable. Opt("GUICloseOnESC", 1) ; 1 = Send the $GUI_EVENT_CLOSE message when ESC is pressed (default). Opt('MustDeclareVars', 1) Global $hListView, $hListView2 _Example1() While 1 Sleep(3000) WEnd Func _Example1() Local $hImage, $aIcons[3] = [0, 3, 6] Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER) GUICreate("ListView Sort", 300, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI") $hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180, -1, $iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle) GUICtrlSetOnEvent($hListView, "sort") ; Load images $hImage = _GUIImageList_Create(18, 18, 5, 3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -7) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -12) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -4) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -5) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -6) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -9) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -10) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -11) _GUICtrlListView_SetImageList($hListView, $hImage, 1) _AddRow($hListView, "ABC|000666|10.05.2004", $aIcons) _AddRow($hListView, "DEF|444|11.05.2005", $aIcons, 1) _AddRow($hListView, "CDE|555|12.05.2004", $aIcons, 2) GUISetState() _GUICtrlListView_RegisterSortCallBack($hListView) EndFunc ;==>_Example1 Func sort() _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView)) EndFunc ;==>sort Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0) Local $aItem = StringSplit($sItem, "|") Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 9999) _GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER) For $x = 2 To $aItem[0] _GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus) _GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE) Next EndFunc ;==>_AddRow Func CloseGUI() _GUICtrlListView_UnRegisterSortCallBack($hListView) GUIDelete() Exit EndFunc ;==>CloseGUI
PartyPooper Posted November 30, 2009 Author Posted November 30, 2009 Ahhh ok, now I understand what's happening. Thanks Picaxe
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now