benners Posted November 30, 2013 Share Posted November 30, 2013 Problem I am trying to sort a list view with checkboxes in descending order. The _GUICtrlListView_SimpleSort function works as intended but upon first sort if all the checkboxes are uncheck when the sort is complete the item that was at index 0 is checked. This seems to be a problem when __GUICtrlListView_GetCheckedIndices used by the simplesort returns a blankempty result. It's not often I look at the default includes, I'm normally just happy functions work but there is some code in the sorting function in GuiListView.au3 that checks for comparision and if the items match then the checked state is set to True, For $Z = 1 To $i_checked[0] If $a_lv[$x][UBound($a_lv, 2) - 1] = $i_checked[$Z] Then _GUICtrlListView_SetItemChecked($hWnd, $x, True) ExitLoop EndIf Next This comparison is correct as ithe first index (0) matches the __GUICtrlListView_GetCheckedIndices returned string (blank seen as 0) to it is assumed that the checkbox is to be selected. The __GUICtrlListView_GetCheckedIndices seems to be longer than required and uses Redim inside a loop which, from information picked up on the forum, is a not ideal. I have searched on the bug tracker for tickets related to _GUICtrlListView_SimpleSort and they're all closed and the latest beta performs the same, so this may not be a problem. I know that _GUICtrlListView_RegisterSortCallBack sorts checkbox items correctly and the checked state remain the same but this would mean more code and probably my own sorting function to sort desecending by default. My Solution I have used the simplesort example from the help file and removed code I don't need and have also added __GUICtrlListView_SimpleSort to enable use of a shortened _GUICtrlListView_GetCheckedIndices that does not alter the checkbox state when sorting. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work Global $hListView _Main() Func _Main() GUICreate("ListView SimpleSort", 400, 300) $hListView = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_CHECKBOXES, $LVS_EX_CHECKBOXES) ; added GUICtrlCreateListViewItem("line4|5|more_a", $hListView) GUICtrlCreateListViewItem("line5|4.50 |more_c", $hListView) GUICtrlCreateListViewItem("line5|4.0 |more_c", $hListView) GUICtrlCreateListViewItem("line3|23|more_e", $hListView) GUICtrlCreateListViewItem("line2|0.34560 |more_d", $hListView) GUICtrlCreateListViewItem("line1|1.0 |more_b", $hListView) GUICtrlCreateListViewItem("line1|0.1 |more_b", $hListView) GUICtrlCreateListViewItem("line1|10|more_b", $hListView) _GUICtrlListView_SetColumnWidth($hListView, 0, 75) _GUICtrlListView_SetColumnWidth($hListView, 1, 75) _GUICtrlListView_SetColumnWidth($hListView, 2, 75) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ;~ _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; original help file line __GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; line to use reworked function EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlListView_SimpleSort ; Description ...: Sorts a list-view control (limited) ; Syntax.........: _GUICtrlListView_SimpleSort($hWnd, ByRef $vDescending, $iCol) ; Parameters ....: $hWnd - Handle to the control ; $vDescending - Can be: ; | True - Sort Descending ; | False - Sort Ascending ; +Array - With the following format: ; |[0] - First Column ; |[1] - Second Column ; |[n] - Last Column ; $iCol - Column number ; Return values .: None ; Author ........: Gary Frost (gafrost) ; Modified.......: ; Remarks .......: This is a basic sort fuction, for advanced sort see GUICtrlRegisterListViewSort ; Related .......: GUICtrlRegisterListViewSort ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func __GUICtrlListView_SimpleSort($hWnd, ByRef $vDescending, $iCol) If $Debug_LV Then __UDF_ValidateClassName($hWnd, $__LISTVIEWCONSTANT_ClassName) If _GUICtrlListView_GetItemCount($hWnd) Then Local $b_desc If (IsArray($vDescending)) Then $b_desc = $vDescending[$iCol] Else $b_desc = $vDescending EndIf Local $columns = _GUICtrlListView_GetColumnCount($hWnd) Local $items = _GUICtrlListView_GetItemCount($hWnd) Local $temp_item = "" Local $SeparatorChar = Opt('GUIDataSeparatorChar') For $x = 1 To $columns $temp_item = $temp_item & " " & $SeparatorChar Next $temp_item = StringTrimRight($temp_item, 1) Local $a_lv[$items][$columns + 1] Local $i_selected = StringSplit(_GUICtrlListView_GetSelectedIndices($hWnd), $SeparatorChar) Local $i_checked = _GUICtrlListView_GetCheckedIndices($hWnd, $SeparatorChar) ; new line ;~ Local $i_checked = StringSplit(__GUICtrlListView_GetCheckedIndices($hWnd), $SeparatorChar) ; UDF line Local $v_item, $iFocused = -1 For $x = 0 To UBound($a_lv) - 1 Step 1 If $iFocused = -1 Then If _GUICtrlListView_GetItemFocused($hWnd, $x) Then $iFocused = $x EndIf _GUICtrlListView_SetItemSelected($hWnd, $x, False) _GUICtrlListView_SetItemChecked($hWnd, $x, False) For $Y = 0 To UBound($a_lv, 2) - 2 Step 1 $v_item = StringStripWS(_GUICtrlListView_GetItemText($hWnd, $x, $Y), 2) If (StringIsFloat($v_item) Or StringIsInt($v_item)) Then $a_lv[$x][$Y] = Number($v_item) Else $a_lv[$x][$Y] = $v_item EndIf Next $a_lv[$x][$Y] = $x Next _ArraySort($a_lv, $b_desc, 0, 0, $iCol) For $x = 0 To UBound($a_lv) - 1 Step 1 For $Y = 0 To UBound($a_lv, 2) - 2 Step 1 _GUICtrlListView_SetItemText($hWnd, $x, $a_lv[$x][$Y], $Y) Next For $Z = 1 To $i_selected[0] If $a_lv[$x][UBound($a_lv, 2) - 1] = $i_selected[$Z] Then If $a_lv[$x][UBound($a_lv, 2) - 1] = $iFocused Then _GUICtrlListView_SetItemSelected($hWnd, $x, True, True) Else _GUICtrlListView_SetItemSelected($hWnd, $x, True) EndIf ExitLoop EndIf Next For $Z = 1 To $i_checked[0] If $a_lv[$x][UBound($a_lv, 2) - 1] = $i_checked[$Z] Then _GUICtrlListView_SetItemChecked($hWnd, $x, True) ExitLoop EndIf Next Next If (IsArray($vDescending)) Then $vDescending[$iCol] = Not $b_desc Else $vDescending = Not $b_desc EndIf EndIf EndFunc ;==>__GUICtrlListView_SimpleSort Func _GUICtrlListView_GetCheckedIndices($hWnd, $sDelim) If $Debug_LV Then __UDF_ValidateClassName($hWnd, $__LISTVIEWCONSTANT_ClassName) Local $aIndices[1] = [0] ; empty array for return if no items checked Local $sIndices = '' For $i = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1 If _GUICtrlListView_GetItemChecked($hWnd, $i) Then $sIndices &= $i & $sDelim Next If Not $sIndices Then Return $aIndices ; return the empty array if the string is blank Return StringSplit(StringTrimRight($sIndices, StringLen($sDelim)), $sDelim) EndFunc ;==>_GUICtrlListView_GetCheckedIndices If there is a better way to do the above using the standard includes?. Searching the forum I found guiness has done a similar function to get checked states here and based mine on his. Question What are the reasons for sending an array as the $B_DESCENDING parameter rather than TrueFalse Thanks Link to comment Share on other sites More sharing options...
guinness Posted November 30, 2013 Share Posted November 30, 2013 This should be fixed in the AutoIt beta. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2013 Moderators Share Posted November 30, 2013 (edited) benners,Nice - I can see nothing wrong with your solution. There must have been a good reason why the function needed to return either an array or a string at one time, but as it stands now it is only ever called at this one point from within the GUIListView include - so I see no point in retaining that level of internal complexity. As to why $B_DESCENDING should be an aray, it needs to cover all the columns - one per element. If you do not store the result of the last sort, then Windows and AutoIt assume that the next sort of that column should be ascending regardless of what the user thinks. I fell foul of this in my GUIListViewEx UDF where the parameter was only Local and so not retained between sorts. Clear now? M23P.S. I will move this thread to "Dev Chat" where it will not get hidden among the other general threads and others more versed in UDF coding than I can comment.Edit: guinness, the problem still exists in the .23 Beta when I tested. Edited November 30, 2013 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
guinness Posted November 30, 2013 Share Posted November 30, 2013 There was an issue I fixed ages ago (back in 2012) but seems it was a different issue - #1996. Sorry about that. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
benners Posted November 30, 2013 Author Share Posted November 30, 2013 (edited) Thanks for the replies. I can also confirm that the problem exists in the latest beta v3.3.9.23. Looking at the beta GuiListView.au3 the problem code seems the same. Although __GUICtrlListView_GetCheckedIndices never returns an array if it does then _GUICtrlListView_SimpleSort will try to stringsplit it. @Melba23 Thought I was losing it then when I couldn't find my post lol and thanks for the explanation Edited November 30, 2013 by benners Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2013 Moderators Share Posted November 30, 2013 benners,Here is my suggested replacement function. It uses just an array, rather than an array and a string, and so I have removed the $iDelim parameter as it is no longer required:expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work Global $hListView _Main() Func _Main() GUICreate("ListView SimpleSort", 400, 300) $hListView = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_CHECKBOXES, $LVS_EX_CHECKBOXES) ; added GUICtrlCreateListViewItem("line4|5|more_a", $hListView) GUICtrlCreateListViewItem("line5|4.50 |more_c", $hListView) GUICtrlCreateListViewItem("line5|4.0 |more_c", $hListView) GUICtrlCreateListViewItem("line3|23|more_e", $hListView) GUICtrlCreateListViewItem("line2|0.34560 |more_d", $hListView) GUICtrlCreateListViewItem("line1|1.0 |more_b", $hListView) GUICtrlCreateListViewItem("line1|0.1 |more_b", $hListView) GUICtrlCreateListViewItem("line1|10|more_b", $hListView) _GUICtrlListView_SetColumnWidth($hListView, 0, 75) _GUICtrlListView_SetColumnWidth($hListView, 1, 75) _GUICtrlListView_SetColumnWidth($hListView, 2, 75) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort_Mod($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; line to use reworked function EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _GUICtrlListView_SimpleSort_Mod($hWnd, ByRef $vDescending, $iCol) If $Debug_LV Then __UDF_ValidateClassName($hWnd, $__LISTVIEWCONSTANT_ClassName) If _GUICtrlListView_GetItemCount($hWnd) Then Local $b_desc If (IsArray($vDescending)) Then $b_desc = $vDescending[$iCol] Else $b_desc = $vDescending EndIf Local $columns = _GUICtrlListView_GetColumnCount($hWnd) Local $items = _GUICtrlListView_GetItemCount($hWnd) Local $temp_item = "" Local $SeparatorChar = Opt('GUIDataSeparatorChar') For $x = 1 To $columns $temp_item = $temp_item & " " & $SeparatorChar Next $temp_item = StringTrimRight($temp_item, 1) Local $a_lv[$items][$columns + 1] Local $i_selected = StringSplit(_GUICtrlListView_GetSelectedIndices($hWnd), $SeparatorChar) Local $i_checked = _GUICtrlListView_GetCheckedIndices_Mod($hWnd) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $v_item, $iFocused = -1 For $x = 0 To UBound($a_lv) - 1 Step 1 If $iFocused = -1 Then If _GUICtrlListView_GetItemFocused($hWnd, $x) Then $iFocused = $x EndIf _GUICtrlListView_SetItemSelected($hWnd, $x, False) _GUICtrlListView_SetItemChecked($hWnd, $x, False) For $Y = 0 To UBound($a_lv, 2) - 2 Step 1 $v_item = StringStripWS(_GUICtrlListView_GetItemText($hWnd, $x, $Y), 2) If (StringIsFloat($v_item) Or StringIsInt($v_item)) Then $a_lv[$x][$Y] = Number($v_item) Else $a_lv[$x][$Y] = $v_item EndIf Next $a_lv[$x][$Y] = $x Next _ArraySort($a_lv, $b_desc, 0, 0, $iCol) For $x = 0 To UBound($a_lv) - 1 Step 1 For $Y = 0 To UBound($a_lv, 2) - 2 Step 1 _GUICtrlListView_SetItemText($hWnd, $x, $a_lv[$x][$Y], $Y) Next For $Z = 1 To $i_selected[0] If $a_lv[$x][UBound($a_lv, 2) - 1] = $i_selected[$Z] Then If $a_lv[$x][UBound($a_lv, 2) - 1] = $iFocused Then _GUICtrlListView_SetItemSelected($hWnd, $x, True, True) Else _GUICtrlListView_SetItemSelected($hWnd, $x, True) EndIf ExitLoop EndIf Next For $Z = 1 To $i_checked[0] If $a_lv[$x][UBound($a_lv, 2) - 1] = $i_checked[$Z] Then _GUICtrlListView_SetItemChecked($hWnd, $x, True) ExitLoop EndIf Next Next If (IsArray($vDescending)) Then $vDescending[$iCol] = Not $b_desc Else $vDescending = Not $b_desc EndIf EndIf EndFunc ;==>_GUICtrlListView_SimpleSort_Mod Func _GUICtrlListView_GetCheckedIndices_Mod($hWnd) Local $iCount = _GUICtrlListView_GetItemCount($hWnd) ; Create max size array Local $aSelected[$iCount + 1] = [0] For $i = 0 To $iCount - 1 If _GUICtrlListView_GetItemChecked($hWnd, $i) Then $aSelected[0] += 1 $aSelected[$aSelected[0]] = $i EndIf Next ; Remove unfilled elements ReDim $aSelected[$aSelected[0] + 1] Return $aSelected EndFunc ;==>_GUICtrlListView_GetCheckedIndices_ModNote the trick to limit the function to a single ReDim - you may find it useful elsewhere, I use it all the time. All,Can others try this script and check it works for them too - and/or comment on the code. Once we have some confirmation that it does indeed work I will approach the powers-that-be to get it added to the next Beta. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
guinness Posted November 30, 2013 Share Posted November 30, 2013 (edited) I will test, but that code is from the stable version and not the beta .23. Edit: Issue is fixed. Edited November 30, 2013 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2013 Moderators Share Posted November 30, 2013 guinness,Excellent. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
benners Posted November 30, 2013 Author Share Posted November 30, 2013 Melba23, Thanks, code works as expected. Also added _GUICtrlListView_GetCheckedIndices_Mod func to beta GuiListView.au3 and updated beta _GUICtrlListView_SimpleSort func with Local $i_checked = _GUICtrlListView_GetCheckedIndices_Mod($hWnd) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< and Beta ran it, the example still works. When checking the beta GuiListView.au3 using SciTE and SyntaxCheck Beta there is a syntax error regarding an illegal character '?' and ':' is this OK?, it's not related to the new code "C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /beta /AU3Check /in "C:\Program Files\AutoIt3\Beta\IncludeStructureConstants.au3" +>16:49:31 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0409 Keyboard:00000809 OS:WIN_XP/Service Pack 3 CPU:X64 OS:X86) >Running AU3Check (1.54.22.0) from:C:Program FilesAutoIt3 C:\Program Files\AutoIt3\Beta\IncludeStructureConstants.au3(1820,89) : ERROR: syntax error (illegal character) "uint cyIntegral;uint cxIdeal;lparam lParam;uint cxHeader" & ((@OSVersion = "WIN_XP") ? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2013 Moderators Share Posted November 30, 2013 benners,The error is caused by the new ternary syntax in the Beta - the 3.3.8.1 Au3Check cannot cope with it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 1, 2013 Moderators Share Posted December 1, 2013 benners,New code committed and your name is now part of the GUIListView.au3 include file that is installed with AutoIt - a day to mark in your diary! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
benners Posted December 2, 2013 Author Share Posted December 2, 2013 benners, New code committed and your name is now part of the GUIListView.au3 include file that is installed with AutoIt - a day to mark in your diary! M23 Well I'd like to thank everybody who made this possible *sob* /speech But seriously, thanks. It's not much, but if I can do some of the leg work to help yourself and others involved in this project I'm happy to do it Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 2, 2013 Moderators Share Posted December 2, 2013 benners,Anyone who offers explanations and possible solutions rather than just pointing out problems will always be welcome. I know this is not possible for the code code, but the UDFs are available for everyone to examine and suggestions are never just ignored without careful consideration. So thanks again - you deserved it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
guinness Posted December 2, 2013 Share Posted December 2, 2013 Here here. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
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