Search the Community
Showing results for tags 'Sort'.
-
Hello Everyone I have a strange issue ... The json generated array is not getting sorted properly for some reason #include <json.au3> #include <Array.au3> Dim $Chart[0][2] ; Array size of 2 columns $object = json_decode(FileRead("Test.json")) ;for local testing $Coins = json_get($object, '.data') for $i = 0 to UBound($Coins) -1 $name = json_get($object, '.data[' & $i & '].name' ) $change_1h = json_get($object, '.data[' & $i & '].quote.USD.percent_change_1h') _ArrayAdd($Chart,$name & "|" & number($change_1h,3) ) Next _ArraySort($Chart, 1, Default, Default, 1) _ArrayDisplay($Chart) _ArraySort is sorting the array like this (wrong): However if i click on the "Col 1" header it will be sorted correctly: How can i make _ArraySort sort them like clicking on "Col 1" does ? PS: i tried using the function "Number()" when i add the value to the array , but same result .. Thanks in advance Test.json
-
Code is simple/selfexplanatory ... #include "Array.au3" $a = StringSplit('aaa,b,cc', ',', 2) ; no_count _ArraySortLen($a) _ArrayDisplay($a, '$a - without count') $b = StringSplit('aaa,b,cc', ',') _ArraySortLen1($b) _ArrayDisplay($b, '$b - with count') ; zero based array (without count at [0]) Func _ArraySortLen(ByRef $aArr, $iDescending = 0) Local $j = UBound($aArr)-1 Local $aTemp[$j+1][2] For $i = 0 To $j $aTemp[$i][0] = StringLen($aArr[$i]) $aTemp[$i][1] = $aArr[$i] Next _ArraySort($aTemp,$iDescending) For $i = 0 To $j $aArr[$i] = $aTemp[$i][1] Next EndFunc ; one based array (with count at [0]) Func _ArraySortLen1(ByRef $aArr, $iDescending = 0) Local $j = $aArr[0] Local $aTemp[$j+1][2] For $i = 1 To $j $aTemp[$i][0] = StringLen($aArr[$i]) $aTemp[$i][1] = $aArr[$i] Next _ArraySort($aTemp,$iDescending,1) For $i = 1 To $j $aArr[$i] = $aTemp[$i][1] Next EndFunc
-
Please help me sort the directory tree by level. I want to sort the folders in order: 6-> 5> 4> 3> 2> 1 Thanks for all the help and suggestions! #include <File.au3> #include <Array.au3> Global Const $sRemotePath = '/user/trong/sync' Global Const $sLocalPath = @MyDocumentsDir _Sequential($sLocalPath, $sRemotePath) Func _Sequential($iLocalPath, $iRemotePath) $iLocalPath = StringReplace($iLocalPath, "/", "\") $iRemotePath = StringReplace($iRemotePath, "\", "/") If (StringRight($iLocalPath, 1) = "\") Then $iLocalPath = StringTrimRight($iLocalPath, 1) ConsoleWrite("> From: " & $iLocalPath & @CRLF) ConsoleWrite("> TO: " & $iRemotePath & @CRLF) Local $aDirList = _FileListToArrayRec($iLocalPath, '*', $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) If (Not @error) And IsArray($aDirList) Then For $d = 1 To $aDirList[0] ConsoleWrite("! Current Path (" & $d & '/' & $aDirList[0] & '): ' & $aDirList[$d] & @CRLF) Local $aFileList = _FileListToArray($aDirList[$d], '*', $FLTA_FILES, False) If (Not @error) And IsArray($aFileList) Then For $f = 1 To $aFileList[0] ConsoleWrite("+ File: (" & $f & '/' & $aFileList[0] & ') ON Path ' & $d & '/' & $aDirList[0] & @CRLF) Local $iPathName = StringReplace($aDirList[$d], $iLocalPath & '\', '') Local $iFileName = _SplitPath($aFileList[$f], 5) Local $iRemoteDir = StringReplace($iRemotePath & '/' & $iPathName, '\', '/') Local $iRemoteFile = StringReplace($iRemoteDir & '/' & $iFileName, '\', '/') Local $iLocalFile = $aDirList[$d] & '\' & $iFileName ConsoleWrite("- Path Name : " & $iPathName & @CRLF) ConsoleWrite("- File Name : " & $iFileName & @CRLF) ConsoleWrite("- Remote Dir : " & $iRemoteDir & @CRLF) ConsoleWrite("- Remote File: " & $iRemoteFile & @CRLF) ConsoleWrite("- Local File : " & $iLocalFile & @CRLF) ;~ _FTP_DirCreate($iRemotePath & '\' & $iPathName) ;~ _FTP_ProgressUpload($hFTPSession, $aDirList[$d] & '\' & $iFileName, $iRemotePath & '\' & $iPathName) Next EndIf Next EndIf EndFunc ;==>_Sequential Func _IsFile($sPath) If Not FileExists($sPath) Then Return SetError(1, 0, -1) If StringInStr(FileGetAttrib($sPath), 'D') <> 0 Then Return SetError(0, 0, 0) ;IsDir Else Return SetError(0, 0, 1) ;IsFile EndIf EndFunc ;==>_IsFile Func _SplitPath($sFilePath, $sReturnType = 0) Local $sDrive, $sDir, $sFileName, $sExtension Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1) If @error Then ; This error should never happen. ReDim $aArray[5] $aArray[0] = $sFilePath EndIf $sDrive = $aArray[1] If StringLeft($aArray[2], 1) == "/" Then $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/") Else $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\") EndIf $sFileName = $aArray[3] $sExtension = $aArray[4] If $sReturnType = 0 Then Return $aArray If $sReturnType = 1 Then Return $sDrive If $sReturnType = 2 Then Return $sDir If $sReturnType = 3 Then Return $sFileName If $sReturnType = 4 Then Return $sExtension Local $fName = $sFileName & $sExtension If $sReturnType = 5 Then Return $fName Local $zName = $sDrive & $sDir If $sReturnType = 6 Then Return $zName ; By Dao Van Trong - TRONG.LIVE EndFunc ;==>_SplitPath
-
Hi, i have this array of numbers in the form of strings, and i assumed _arraysort would sort them out, but theres no option to do it numerically, so i had to do it another way, seems clumsy, what am i missing here? There's for sure a better way to sort this out numerically right? _arraysort is doing a mess with the numbers, it goes like this: 35,45,50,42,48,54 #include<Array.au3> Local $ID, $AM Local $FO = Fileopen('mult.txt') Local $FR = FileReadToArray($FO) FileClose($FO) _ArrayDisplay($FR) For $d = 0 To UBound($FR) $AM = _ArrayMin($FR, 1) ConsoleWrite($AM &@CRLF) $ID = _ArraySearch($FR, $AM) _ArrayDelete($FR, $ID) Next So this way i retrieve the lowest number and then delete it from the array, what would you do? mult.txt
-
Hi, Recently I have had the need to do a sort and then do a second sort while the item of the first sort stays the same ( double sorting , first on column x then while column x is the same sort column y). I did not put much efffort into error checking but so far I did not need it. For my applications so far it works perfectly however if someone is willing I want to test this extensivly. If anyone has big lists of random stuff to sort could you try this out please? #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArraySort_Double ; Description ...: ; Syntax ........: _ArraySort_Double (Byref $array[, $first_index = Default[, $second_index = Default[, $ascending = Default]]]) ; Parameters ....: $array - 2d array to sort. ; $first_index - [optional] first column to sort. Default is 0. ; $second_index - [optional] second column to sort. Default is 1. ; $ascending - [optional] ascending/descending. Default is 1. ; Return values .: 1 if no errors occured , -1 if errors occured ; Author ........: Ternal ; Remarks .......: Needs excessive testing. ; Related .......: _arraysort() ; =============================================================================================================================== Func _ArraySort_Double (byref $array, $first_index = Default, $second_index = Default, $ascending = Default) Local $temp_value Local $counter = 1 If UBound($array, $UBOUND_DIMENSIONS) <> 2 Then MsgBox(0, "error", "error") return -1 EndIf If $first_index = Default Then $first_index = 0 If $second_index = Default Then $second_index = 1 If $ascending = Default Then $ascending = 1 _ArraySort($array, $ascending, 0, 0, $first_index); you can alter settings of primary sort here If @error Then MsgBox(0, "error", @error) return -1 EndIf $temp_value = $array[0][$first_index] For $x = 1 to UBound($array, 1) - 1 If Mod( $x, 10000) = 0 Then ConsoleWrite("at " & $x & " of a total : " & UBound($array, 1) & @CRLF) If $array[$x][$first_index] = $temp_value Then $counter+= 1 If $x = UBound($array, 1) - 1 Then; do last line here(if last line is not a new item) _ArraySort($array, $ascending, $x - $counter, $x, $second_index);you can alter settings of secondary sort here(don't forget to place line 34 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf EndIf Else If $counter > 0 Then ;at least 2 of the same _ArraySort($array, $ascending, $x - $counter, $x - 1, $second_index);you can alter settings of secondary sort here(don't forget to place line 29 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf $counter = 1 EndIf EndIf $temp_value = $array[$x][$first_index] Next Return 1 EndFunc Kind regards, Ternal
- 8 replies
-
- _arraysort()
- array
-
(and 2 more)
Tagged with:
-
The help text for the _ArrayDisplay function says: "Clicking on a column header sort it." I'm wondering why the sorting of hex numbers (specifically window handles like 0x12345678) is so wonky. Sample script: #include <Array.au3> Local $aList = WinList() _ArrayDisplay($aList) Clicking on the Col1 header to sort by window handle doesn't properly sort the list. As a workaround, I'm sorting the array by window handle before displaying it using _ArraySort. But I still wonder what's up with the ListView sorting. Workaround: #include <Array.au3> Local $aList = WinList() _ArraySort($aList, 0, 1, 0, 1) _ArrayDisplay($aList)
-
I am tracking this topic by @LarsJ. It is very advanced and overkill for what I am currently trying to do. Problem is this. Listview contains columns, one of which is right aligned and gets populated by float values, such as 123.99. Some do not have decimals ie 124.00 and on sort gets truncated to 124. Its obviously still the same value, but the display has reset. ; line below is for list VIEW ;..................................0.........1......2............ $cListView = GUICtrlCreateListView("CUSTOMER|AMOUNT|DESCRIPTION", 8, 152, 764, 279) GUICtrlSetBkColor($cListView, $GUI_BKCOLOR_LV_ALTERNATE) ; alternate between the listview background color and the listview item background color GUICtrlSetBkColor($cListView, $LVStdClr) ; Set the background color for the listview _GUICtrlListView_SetColumnWidth($cListView, 0, 120) ; -- the client name _GUICtrlListView_SetColumnWidth($cListView, 1, 90) ;-- the amount _GUICtrlListView_JustifyColumn($cListView, 1, 1) ; 1 - Text is right aligned _GUICtrlListView_SetColumnWidth($cListView, 2, 200) ; the description What I am looking for is something native and simple like a _GUICtrlListView_SetColumnFormat($cListView, 1, "%.2f") ; 1 - column is stringformatted to "%.2f" So that after each sort it will appear as it was in the original rendering. Is there something like this? I have not been able to find a simple solution. Thanks. Skysnake
-
I have a list of filenames and their versions and I want to sort them by the versions. However, they always sort like they were just strings. The version numbers can have up to 4 components (eg: 1.22.3.4). I want version '1.2.7' to sort ahead of '1.12.7', and '1.8 alpha' to sort ahead of '1.8 beta' Here's my array of items to be sorted: 1.5 alpha.22.1\filexxx 1.9\filexxx 1.8beta\filexxx 1.8alpha\filexxx 1.6\filexxx 1.62\filexxx 1.5-alpha.2.1\filexxx 1.2\filexxx 1.11-beta\filexxx I want the sorted list to look like this: 1.2\filexxx 1.5-alpha.2.1\filexxx 1.5 alpha.22.1\filexxx 1.6\filexxx 1.62\filexxx 1.8alpha\filexxx 1.8beta\filexxx 1.9\filexxx 1.11-beta\filexxx But, what I end up with is this: 1.2\filexxx 1.6\filexxx 1.9\filexxx 1.62\filexxx 1.8beta\filexxx 1.8alpha\filexxx 1.11-beta\filexxx 1.5 alpha.22.1\filexxx 1.5-alpha.2.1\filexxx Here is my test script: #include <Debug.au3> _DebugSetup(@ScriptName & "_debug.txt", False, 5, "") _DebugOut("=============== " & @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ====================" & @CRLF) #include <Array.au3> #include <String.au3> test() Func test() Local $ar $ar = StringSplit("", "") _ArrayAdd($ar, "1.5 alpha.22.1\filexxx") _ArrayAdd($ar, "1.9\filexxx") _ArrayAdd($ar, "1.8beta\filexxx") _ArrayAdd($ar, "1.8alpha\filexxx") _ArrayAdd($ar, "1.6\filexxx") _ArrayAdd($ar, "1.62\filexxx") _ArrayAdd($ar, "1.5-alpha.2.1\filexxx") _ArrayAdd($ar, "1.2\filexxx") _ArrayAdd($ar, "1.11-beta\filexxx") dumparray($ar, "$ar - initial values") setupVerSort($ar) ; Prepend each item in the array with a formatted version number dumparray($ar, "$ar - after setup") _ArraySort($ar, 0, 1) ; Sort based on the formatted version numbers cleanupVerSort($ar) ; Strip off the formatted version numbers dumparray($ar, "$ar - after cleanup") EndFunc ;==>test ; For each item in the array, extract the version number part, format it for sorting ; and put the formatted version in front of the item string (separated by " + ") Func setupVerSort(ByRef $ar) Local $ndx, $ndx2, $verIN, $verOUT, $vpartIN, $vpartOUT, $parts, $maxdepth $maxdepth = 4 For $ndx = 1 To UBound($ar) - 1 $verIN = StringSplit($ar[$ndx], "\", 2)[0] ; Get the version number $parts = StringSplit($verIN, '.', 2) ; Split the components into the $parts array redim $parts[$maxdepth] ; Only look at $maxdepth version components ; Format each component to be a set character length (8) For $ndx2 = 0 To UBound($parts) - 1 $vpartIN = $parts[$ndx2] If (StringRegExp($vpartIN, "[a-zA-Z]+")) Then $vpartOUT = StringRegExpReplace($vpartIN, "([a-zA-Z])*", "\0") logmsg("$vpartIN ==>" & $vpartIN & "<==, $vpartOUT ==>" & $vpartOUT & "<==") logmsg("") Else $vpartOUT = $vpartIN EndIf $parts[$ndx2] = StringFormat("%8s", $vpartOUT) ; Format this conponent to be 8 characters wide Next $verOUT = _ArrayToString($parts, ".", 0) $ar[$ndx] = $verOUT & " + " & $ar[$ndx] ; Prepend the formatted version Next EndFunc ;==>setupVerSort Func cleanupVerSort(ByRef $ar) Local $x For $ndx = 1 To UBound($ar) - 1 $x = StringInStr($ar[$ndx], " + ") $ar[$ndx] = StringTrimLeft($ar[$ndx], $x + 2) ; Strip off the formatted version Next EndFunc ;==>cleanupVerSort Func logmsg($msg, $lnum = @ScriptLineNumber) Local $str = ":" & $lnum & ": " & $msg ; Caller's line number plus the caller's message ; Send to both the Console and to DebugOut() _DebugOut($str) ConsoleWrite($str & @CRLF) EndFunc ;==>logmsg Func dumparray(ByRef $ar, $sTitle, $lnum = @ScriptLineNumber) Local $str = @CRLF & " -" & $lnum & "-" & " Dump of " & $sTitle & @CRLF If (IsArray($ar)) Then For $ndx = 0 To UBound($ar) - 1 $str &= " [" & $ndx & "] " & $ar[$ndx] & @CRLF Next Else $str = "<not an array>" EndIf logmsg($str) EndFunc ;==>dumparray
-
Hi, I have a 2D array with 2 columns, the 1st column contains a "version string" and the 2nd column contains a generic string. I want to sort it in the descending order so the latest version comes first. #include <Array.au3> Local $aVersionsAndReleases[4][2] = [["0.2.8.9", "Release #1"], ["0.2.9.10", "Release #3"], ["0.2.9.11", "Release #4"], ["0.2.8.10", "Release #2"]] _ArraySort($aVersionsAndReleases, 1) ConsoleWrite(_ArrayToString($aVersionsAndReleases, ' - ')) _ArrayDisplay($aVersionsAndReleases) Unfortunately, _ArraySort isn't working here . This is the output generated by the script: 0.2.9.11 - Release #4 0.2.9.10 - Release #3 0.2.8.9 - Release #1 0.2.8.10 - Release #2 The expected result should be: 0.2.9.11 - Release #4 0.2.9.10 - Release #3 0.2.8.10 - Release #2 0.2.8.9 - Release #1 I am looking to develop an function which does this... but I don't know where to start . Can someone help me get started? Thanks in Advance! - TD.
-
Hello guys, I'm working with a simple script, complementing a GUICtrlCreateListView which has 5 columns. I would order the first column so that the numbers are decreasing. #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("line10|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) #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) _GUICtrlListView_UnRegisterSortCallBack($search_LV) Local $ColumnSorted = DllStructGetData($tInfo, 'SubItem') If $ColumnSorted = 1 Then ConsoleWrite('Numeric: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, True) & @CRLF) Else ConsoleWrite('Literal: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, False) & @CRLF) EndIf _GUICtrlListView_SortItems($search_LV, DllStructGetData($tInfo, 'SubItem')) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Ordering the "String" column, you notice that the line "line10" is not ordered last. And 'possible to order the "String" column in descending order? thank you very much
-
Hi guys, I wonder if there is a way to sort the filelist in an array from _FileListToArray () when files have the regular Windows enumeration example: File1 (1), File2 (2), File3 (3), etc. I'm posting two sample graphics so you can see what I mean I would like to get my list like in graphic 2 right now I'm getting my list like in graphic 1 which is the something I don't like. It's worth to say that I have no problem with a list when the files's names start with a number or is just a number thanks to the code found in this post. But, the problem is still present if I just get rid of the parenthesis that is () so in other words the problem happens when the enumeration is at the end of the names whether parenthesis are present or not.
-
I want to coding a excel sort,scheduling system. When I input orgin file,and choose times(example is 7 times(A -->G)) system will output excel. (rule: 1 time include 1 Name ,but Food can't Repeat. secend's Food can't overlap with previous) How to codng of it ?!!!! Thank you veryvery much!!!!!! test.xlsx
-
Hi I'am trying to list files from folder sorted by name (same as the picture) i tried this code #include <File.au3> $arr = _FileListToArray("D:\2") _ArrayDisplay($arr) i am getting this result Any one could explain why it is putting 10-1 before 8-1 ? how can i make Autoit view file same as windows explorer ?
- 20 replies
-
- sort
- _FileListToArray
-
(and 1 more)
Tagged with:
-
Hi guys, I am using an old version of Excel.au3 which I am not ready to update yet so please help me. The old Excel.au3 does not have any method for SORT. I attempted to create one since i need one but I am getting an error. Here's my sample code: $oAppl.Activesheet.UsedRange.sort($oAppl.Activesheet.cells(1,5),1,1) I thought this would work but I get the : ==> The requested action with this object has failed.: $oAppl.Activesheet.UsedRange.sort($oAppl.Activesheet.cells(1,$BidDayColNumber),1,1) $oAppl.Activesheet.UsedRange.sort($oAppl.Activesheet.cells(1,$BidDayColNumber),1,1)^ ERROR Any ideas or alternatives on sorting a range without calling from Excel.au3?
-
Hello all, Back again it seems. I've hit a snag in the below script. I use this on win 7 and XP machines frequently and have just realized that sorting using column headers is not 'working' (is not updating listview; it looks like something is going on behind the scenes..) when clicked. Also this does not show the sorting arrow when using the callback sort functionality. So, to sum up, I am not seeing the arrow keys when clicking the column header to sort. And, it is not sorting the values in the $List1 ListView box on a win XP machine. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <Constants.au3> #include <GUIListBox.au3> #include <GUIEdit.au3> #include <GuiListView.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <ScrollBarConstants.au3> #include <GuiScrollBars.au3> Local $List1, $List2, $List3, $List4, $GUIhandle Local $Button19, $Button91, $ButtonAZ, $ButtonZA Local $hChild_1, $cLabel_1, $cLabel_2, $cLabel_3 GUI() Repaint() Local $bSysMsg = False Local $aRect = _GUICtrlListView_GetItemRect($List1, 0) $iDeltaY = $aRect[3] - $aRect[1] _GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH) _GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH) _GUICtrlListView_RegisterSortCallBack($List1) _GUICtrlListView_RegisterSortCallBack($List2) _GUICtrlListView_RegisterSortCallBack($List3) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $GUIhandle Switch $msg[0] Case $GUI_EVENT_CLOSE Quit() EndSwitch If $bSysMsg Then $bSysMsg = False _Resize_ListViews() EndIf Case $hChild_1 Switch $msg[0] Case $GUI_EVENT_CLOSE GUIDelete($hChild_1) EndSwitch EndSwitch WEnd Func Repaint() Local $L1, $L2, $L3 _GUICtrlListView_BeginUpdate($List1) _GUICtrlListView_DeleteAllItems($List1) _GUICtrlListView_BeginUpdate($List2) _GUICtrlListView_DeleteAllItems($List2) _GUICtrlListView_BeginUpdate($List3) _GUICtrlListView_DeleteAllItems($List3) For $Index = 0 To 10 Step 1 $L1 = _GUICtrlListView_AddItem($List1, $Index, $Index) $L2 = _GUICtrlListView_AddItem($List2, $Index, $Index) $L3 = _GUICtrlListView_AddItem($List3, $Index, $Index) Next _GUICtrlListView_SetColumnWidth($List1, 0, $LVSCW_AUTOSIZE) _GUICtrlListView_SetColumnWidth($List2, 0, $LVSCW_AUTOSIZE) _GUICtrlListView_EndUpdate($List1) _GUICtrlListView_EndUpdate($List2) _GUICtrlListView_EndUpdate($List3) EndFunc ;==>Repaint Func Quit() _GUICtrlListView_UnRegisterSortCallBack($List1) _GUICtrlListView_UnRegisterSortCallBack($List2) _GUICtrlListView_UnRegisterSortCallBack($List3) Exit EndFunc ;==>Quit Func GUI() Local $Index, $LV1, $LV2, $LV3, $L1_EX, $L2_EX, $L3_EX $GUIhandle = GUICreate("ArchServer", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window $List1 = _GUICtrlListView_Create($GUIhandle, "Computer Name ", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ;;$ES_READONLY incase you don't want to be able to select text $cLabel_1 = GUICtrlCreateLabel("", 20, 35, 300, 448) GUICtrlSetState($cLabel_1, $GUI_DISABLE) GUICtrlSetResizing($cLabel_1, $GUI_DOCKAUTO) GUICtrlSetBkColor($cLabel_1, $GUI_BKCOLOR_TRANSPARENT) _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE) $List2 = _GUICtrlListView_Create($GUIhandle, "Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) $cLabel_2 = GUICtrlCreateLabel("", 355, 35, 190, 450) GUICtrlSetState($cLabel_2, $GUI_DISABLE) GUICtrlSetResizing($cLabel_2, $GUI_DOCKAUTO) GUICtrlSetBkColor($cLabel_2, $GUI_BKCOLOR_TRANSPARENT) $List3 = _GUICtrlListView_Create($GUIhandle, "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) $cLabel_3 = GUICtrlCreateLabel("", 574, 35, 95, 450) GUICtrlSetState($cLabel_3, $GUI_DISABLE) GUICtrlSetResizing($cLabel_3, $GUI_DOCKAUTO) GUICtrlSetBkColor($cLabel_3, $GUI_BKCOLOR_TRANSPARENT) GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4 GUICtrlSetResizing(-1, $GUI_DOCKSIZE) $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY) GUICtrlSetResizing($List4, $GUI_DOCKAUTO) GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections GUICtrlSetResizing(-1, $GUI_DOCKSIZE) $ActiveConnections = GUICtrlCreateList("0", 625, 486, 30, 30) ;dynamically updating list of connections as they come in GUICtrlSetResizing($ActiveConnections, $GUI_DOCKSIZE) GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUISetState(@SW_SHOW) ;shows the GUI window For $Index = 0 To 10 Step 1 $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1 $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2 $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3 Next EndFunc ;==>GUI Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, _ $ceLines, $cl $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Local Const $iLines = _SendMessage($List1, $LVM_GETTOPINDEX) - _SendMessage($List2, $LVM_GETTOPINDEX) _SendMessage($List2, $LVM_SCROLL, 0, $iLines * $iDeltaY) _SendMessage($List3, $LVM_SCROLL, 0, $iLines * $iDeltaY) Switch $hWndFrom Case $List1 Switch $iCode Case $LVN_COLUMNCLICK _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1)) Case $NM_CLICK $sData = _GUICtrlListView_GetSelectedIndices($List1) _GUICtrlListView_SetItemSelected($List2, $sData, True, False) _GUICtrlListView_SetItemSelected($List3, $sData, True, False) EndSwitch Case $List2 Switch $iCode Case $LVN_COLUMNCLICK _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1)) Case $NM_CLICK $sData = _GUICtrlListView_GetSelectedIndices($List2) _GUICtrlListView_SetItemSelected($List1, $sData, True, False) _GUICtrlListView_SetItemSelected($List3, $sData, True, False) EndSwitch Case $List3 Switch $iCode Case $LVN_COLUMNCLICK _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1)) Case $NM_CLICK $sData = _GUICtrlListView_GetSelectedIndices($List3) _GUICtrlListView_SetItemSelected($List1, $sData, True, False) _GUICtrlListView_SetItemSelected($List2, $sData, True, False) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Func WM_SIZE($hWnd, $msg, $wParam, $lParam) _Resize_ListViews() Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam) Const $SC_MAXIMIZE = 0xF030 Const $SC_RESTORE = 0xF120 Switch $wParam Case $SC_MAXIMIZE, $SC_RESTORE $bSysMsg = True EndSwitch EndFunc ;==>_WM_SYSCOMMAND Func _Resize_ListViews() $aRet = ControlGetPos($GUIhandle, "", $cLabel_1) WinMove($List1, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3]) $aRet = ControlGetPos($GUIhandle, "", $cLabel_2) WinMove($List2, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3]) $aRet = ControlGetPos($GUIhandle, "", $cLabel_3) WinMove($List3, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3]) EndFunc ;==>_Resize_ListViews ;========RESIZE FUNCTIONALITY THANKS TO MELBA All replies are much appreciated!
-
Hi, just a short question. I 've got a lisitview with a few columns and I want to register a different sort for two kinds of columns. I 've got a solution, but I don't think it is a good one. Example : Col A = Names (Strings) Col B = Age (Integers) Right now I'm doing this: 1. _GUICtrlListView_RegisterSortCallBack 2. In my WM_NOTIFY Case GUICtrlGetHandle($search_LV) Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $iLparam) ; Kick off the sort callback ;~ ConsoleWrite('SEARCH_LV Column geklickt' & @LF) ConsoleWrite("Sort: " & DllStructGetData($tInfo, 'SubItem')) If $ColumnSorted <> DllStructGetData($tInfo, 'SubItem') Then _GUICtrlListView_UnRegisterSortCallBack($search_LV) ConsoleWrite('NEU' & @CRLF) EndIf $ColumnSorted = DllStructGetData($tInfo, 'SubItem') If DllStructGetData($tInfo, 'SubItem') = 9 Or DllStructGetData($tInfo, 'SubItem') = 10 Then ConsoleWrite('True: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, True) & @CRLF) Else ConsoleWrite('False ' & _GUICtrlListView_RegisterSortCallBack($search_LV, False) & @CRLF) EndIf _GUICtrlListView_SortItems($search_LV, DllStructGetData($tInfo, 'SubItem')) So, I store the column clicked in a global variable. If the column is clicked again (sort asc or desc) then all is fine, if another column then the one before is clicked, I unregister the callback and create a new one. The new callback (in the if) depends on the column clicked because of the content to sort (strings or numbers). Is there an easier / better way? Do I have to use my own sorting function with GuiCtrlRegisterListViewSort? Edit: It still doesn't work in every case (just noticed). Thanks Mega
-
I have a list view (first two colums are Name and Surname). Now I want to sort the items by alphabet. It should sort the names from A to Z and if the Name is teh shame it should sort it by the surname, too. I know about the _GUICtrlListView_SimpleSort() Function, but that only sorts one column. My problem is, that I want to save a value with the number in the list view (first is number one, second is number two...) in a file so when I need to retreive that value I search for the number of the item in the file. Thank you!
-
I recently managed to make a ListView sort correctly by clicking on it's columns, it does sort items very well but there's a very annoying thing >_< : every time after the items are sorted out, an item gets focused ! After I click a column, one item gets blue'd, like when its selected, even if its not ! Note that this happens only becuase of this function : _GUICtrlListView_SimpleSort Instead, the _GUICtrlListView_SortItems function is not doing this , but because of my luck,I must use _GUICtrlListView_SimpleSort ( but it is faster ) Here's my script to test to see what I mean: #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $Form1 = GUICreate("Form1", 383, 307, 192, 124) $ListView1 = GUICtrlCreateListView("C1|C2|C3", 56, 16, 257, 241) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50) $ListView1_0 = GUICtrlCreateListViewItem("1|5|6", $ListView1) $ListView1_1 = GUICtrlCreateListViewItem("2|7|8", $ListView1) $ListView1_2 = GUICtrlCreateListViewItem("3|9|10", $ListView1) $ListView1_3 = GUICtrlCreateListViewItem("4|11|12", $ListView1) GUISetState(@SW_SHOW) Global $toggle = 1 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ListView1 _GUICtrlListView_SimpleSort($ListView1, $toggle, GUICtrlGetState($ListView1)) EndSwitch WEnd How could I get rid of this item focus ?
-
How can I do to, when I click on on a specific column in a listview control, instead to get clicked/sorted other column. Is this possible ? I already know how to sort a column when I click on it : after the listview control was created, I add this code : _GUICtrlListView_RegisterSortCallBack(-1) I know that a gui can wait for a window event to happen, like a click on a control, but how can this be done to look if I clicked on a specific column and if so then, to sort (a clasic sort ) other column instead o.O ?
-
I have a ListView that is created from a FileRead() using delimiters and then added into the ListView as shown below. Local $src = InetGet($url, $file, 1) $data = FileRead($file) $array = StringSplit($data, ";", 1) FileDelete($file) For $n = 1 To UBound($array) - 1 Step 3 $iItem = _GUICtrlListView_AddItem($ListView, $array[$n]) $a = UBound($array) - 1 If $n + 1 > $a Then ExitLoop Else _GUICtrlListView_AddSubItem($ListView, $iItem, $array[$n + 1], 1) _GUICtrlListView_AddSubItem($ListView, $iItem, $array[$n + 2], 2) EndIf Next $PlayerCount = _GUICtrlListView_GetItemCount($ListView) _GUICtrlListView_SetColumn($ListView, 0, "Name (Online: " & $Count & ")") I was using _GUICtrlListView_SortItems to sort them and it appears to work correctly in that it adds the up and down arrow to the column but nothing moves. I tried another one that involved using DLL's but that didn't work either. Am I missing something or what?