jpam Posted March 22, 2006 Posted March 22, 2006 seems _GUICtrlListViewSort has a bug trying example from doc filled a colum with phone numbers looking like "0621596456" after sort the zero is gone ! This is the result "621596456"
GaryFrost Posted March 22, 2006 Posted March 22, 2006 would a dev please move this to support SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
GaryFrost Posted March 22, 2006 Posted March 22, 2006 jpam said: seems _GUICtrlListViewSort has a bugtrying example from docfilled a colum with phone numbers looking like "0621596456"after sort the zero is gone ! This is the result "621596456" This is a generic sort, to satisfy 99.9% of the users if the data in the column is a number the string is converted to a number and sorted as such, not a bug, but by design.If this is unexceptable for you, you might want to look at the fairly new function GUICtrlRegisterListViewSort SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
jpam Posted March 23, 2006 Author Posted March 23, 2006 gafrost said: This is a generic sort, to satisfy 99.9% of the users if the data in the column is a number the string is converted to a number and sorted as such, not a bug, but by design.If this is unexceptable for you, you might want to look at the fairly new function GUICtrlRegisterListViewSortcan GUICtrlRegisterListViewSort be used on a gui with Opt("GUIOnEventMode", 1)when i test it with Opt("GUIOnEventMode", 1) the script ended with no error message ??? :"> jpam
GaryFrost Posted March 23, 2006 Posted March 23, 2006 (edited) jpam said: can GUICtrlRegisterListViewSort be used on a gui with Opt("GUIOnEventMode", 1) when i test it with Opt("GUIOnEventMode", 1) the script ended with no error message ??? :"> jpam Edit: pay close attention to the sleep time in the main loop, if set too long this seems to make autoit exit expandcollapse popup; ******************************************************* ; Example 1 - sorting 3 column's different ; ******************************************************* #include <GUIConstants.au3> Opt("GUIOnEventMode",1) Global Const $LVFI_PARAM = 0x0001 Global Const $LVIF_TEXT = 0x0001 Global Const $LVM_FIRST = 0x1000 Global Const $LVM_GETITEM = $LVM_FIRST + 5 Global Const $LVM_FINDITEM = $LVM_FIRST + 13 Global Const $LVM_SETSELECTEDCOLUMN = $LVM_FIRST + 140 Dim $nCurCol = -1 Dim $nSortDir = 1 Dim $bSet = 0 Dim $nCol = -1 $hGUI = GUICreate("Test", 300, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Terminate") $lv = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180) GUICtrlSetOnEvent($lv,"_Setsort") GUICtrlRegisterListViewSort($lv, "LVSort"); Register the function "SortLV" for the sorting callback $lvi1 = GUICtrlCreateListViewItem("ABC|666|10.05.2004", $lv) GUICtrlSetImage(-1, "shell32.dll", 7) $lvi2 = GUICtrlCreateListViewItem("DEF|444|11.05.2005", $lv) GUICtrlSetImage(-1, "shell32.dll", 12) $lvi3 = GUICtrlCreateListViewItem("CDE|444|12.05.2004", $lv) GUICtrlSetImage(-1, "shell32.dll", 3) GUISetState() While 1 Sleep ( 10 ) WEnd Func _Terminate() Exit EndFunc Func _Setsort() $bSet = 0 $nCurCol = $nCol GUICtrlSendMsg($lv, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($lv), 0) DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($lv), "int", 0, "int", 1) EndFunc ; Our sorting callback funtion Func LVSort($hWnd, $nItem1, $nItem2, $nColumn) Local $nSort ; Switch the sorting direction If $nColumn = $nCurCol Then If Not $bSet Then $nSortDir = $nSortDir * -1 $bSet = 1 EndIf Else $nSortDir = 1 EndIf $nCol = $nColumn $val1 = GetSubItemText($lv, $nItem1, $nColumn) $val2 = GetSubItemText($lv, $nItem2, $nColumn) ; If it is the 3rd colum (column starts with 0) then compare the dates If $nColumn = 2 Then $val1 = StringRight($val1, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2) $val2 = StringRight($val2, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2) EndIf $nResult = 0 ; No change of item1 and item2 positions If $val1 < $val2 Then $nResult = -1 ; Put item2 before item1 ElseIf $val1 > $val2 Then $nResult = 1 ; Put item2 behind item1 EndIf $nResult = $nResult * $nSortDir Return $nResult EndFunc ; Retrieve the text of a listview item in a specified column Func GetSubItemText($nCtrlID, $nItemID, $nColumn) Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int") DllStructSetData($stLvfi, 1, $LVFI_PARAM) DllStructSetData($stLvfi, 3, $nItemID) Local $stBuffer = DllStructCreate("char[260]") $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi)); Local $stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int") DllStructSetData($stLvi, 1, $LVIF_TEXT) DllStructSetData($stLvi, 2, $nIndex) DllStructSetData($stLvi, 3, $nColumn) DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer)) DllStructSetData($stLvi, 7, 260) GUICtrlSendMsg($nCtrlID, $LVM_GETITEM, 0, DllStructGetPtr($stLvi)); $sItemText = DllStructGetData($stBuffer, 1) $stLvi = 0 $stLvfi = 0 $stBuffer = 0 Return $sItemText EndFunc Edited March 23, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
jpam Posted March 23, 2006 Author Posted March 23, 2006 Thanks gafrost but thats not an option for me i have a big script running in the middle mybe when a use _guictrllistviewsort i can add a new "0" in the listview after sort is this possible ? jpam
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