Jack023 Posted March 9, 2014 Share Posted March 9, 2014 Hello all, I'm struggling with a sorting problem with my Listview: I want be able to sort it by clicking the Names on top. Global $listview = GUICtrlCreateListView("Date |Requests |Impressions |Clicks |CTR |eCPM |Earnings ", 15, 160, 679, 105) func _listview() _GUICtrlListView_DeleteAllItems($listview) GUICtrlSetBkColor($listview, 0xF2F6F7) ;~ _GUICtrlListView_SetBkColor($listview, 0x0000FF) _GUICtrlListView_SetColumnWidth($listview, 0, 85) EndFunc GUICtrlCreateListViewItem($date & " "&"|" &$totalreq&" "&"|" &$totalimpes&" "&"|"& $total_clicks&" "&"|"& $ctr&"% "&"|$"& $ecpm&" "&"|$"& $totalbalance&" ", $listview) Sorry for the weird sentences. Anyway , i tried some sorting things in helpfile but everytime my script will just doing weird because it's doing a while loop. So how to sort them, until i quit the gui or click the "$Button1" button. Link to comment Share on other sites More sharing options...
water Posted March 9, 2014 Share Posted March 9, 2014 According to the help file: "Sorting the list by clicking the column name (as in Explorer) is not currently implemented." My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
BrewManNH Posted March 9, 2014 Share Posted March 9, 2014 I don't see anywhere in the posted code an attempt at sorting the listview. Have you attempted to search for the dozens of examples on the forum of how to do this? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
water Posted March 9, 2014 Share Posted March 9, 2014 To register a sort function please have a look at _GUICtrlListView_RegisterSortCallBack. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 9, 2014 Moderators Share Posted March 9, 2014 Jacko23,You can do it like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> Global $aData[4] = ["2014-03-09|456|201|3|0.45%|$2.94|$0.7654", "2014-03-08|236|231|2|0.65%|$1.25|$1.4321", _ "2014-03-07|566|341|1|0.75%|$4.62|$0.4567", "2014-03-06|786|561|3|0.95%|$6.48|$0.8765"] Global $fSortSense = False ; Set initial ascending sort $hGUI = GUICreate("Test", 500, 500) $cListView = GUICtrlCreateListView("", 10, 10, 480, 400) _GUICtrlListView_AddColumn($cListView, "Date", 80) _GUICtrlListView_AddColumn($cListView, "Requests", 80) _GUICtrlListView_AddColumn($cListView, "Impressions", 80) _GUICtrlListView_AddColumn($cListView, "Clicks") _GUICtrlListView_AddColumn($cListView, "CTR") _GUICtrlListView_AddColumn($cListView, "eCPM") _GUICtrlListView_AddColumn($cListView, "Earnings", 80) For $i = 0 To 3 GUICtrlCreateListViewItem($aData[$i], $cListView) Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $cListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) _GUICtrlListView_SimpleSort($cListView, $fSortSense, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch EndFuncM23 Jack023 and Ambient 2 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...
Jack023 Posted March 9, 2014 Author Share Posted March 9, 2014 Melba, You are awesome! Thanks alot Link to comment Share on other sites More sharing options...
Jack023 Posted March 9, 2014 Author Share Posted March 9, 2014 Sorry, Came to a another problem. Func _RunAllOnStart() _listview() _HasVideoAds() _RegistrationDate() _CompletionRate() _CurrentBalance() _PayoutDate() _ServerDate() _Statistics() _LastRefresh() _ReferralStatus() EndFunc Func _RunAllFunc() GUISetState(@SW_LOCK) _listview() _ReferralStatus() _HasVideoAds() _RegistrationDate() _CompletionRate() _CurrentBalance() _PayoutDate() _ServerDate() _Statistics() _LastRefresh() _listview() GUISetState(@SW_UNLOCK) EndFunc Runallonstart that means when GUI starts up it will run all functions and then the sorting system works. When i click $button1 = Refresh button then it will do the _RunAllFunc. Then my listview is empty for some reason because i added the: func _listview() _GUICtrlListView_DeleteAllItems($listview) GUICtrlSetBkColor($listview, 0xF2F6F7) ;~ _GUICtrlListView_SetBkColor($listview, 0x0000FF) _GUICtrlListView_SetColumnWidth($listview, 0, 85) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") EndFunc Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $listview Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) _GUICtrlListView_SimpleSort($listview, $fSortSense, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch EndFunc So how to fix this? Link to comment Share on other sites More sharing options...
Solution BrewManNH Posted March 9, 2014 Solution Share Posted March 9, 2014 An easier way to sort a ListView. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> Global $aData[4] = ["2014-03-09|456|201|3|0.45%|$2.94|$0.7654", "2014-03-08|236|231|2|0.65%|$1.25|$1.4321", _ "2014-03-07|566|341|1|0.75%|$4.62|$0.4567", "2014-03-06|786|561|3|0.95%|$6.48|$0.8765"] Global $fSortSense = False ; Set initial ascending sort $hGUI = GUICreate("Test", 500, 500) $cListView = GUICtrlCreateListView("", 10, 10, 480, 400) _GUICtrlListView_AddColumn($cListView, "Date", 80) _GUICtrlListView_AddColumn($cListView, "Requests", 80) _GUICtrlListView_AddColumn($cListView, "Impressions", 80) _GUICtrlListView_AddColumn($cListView, "Clicks") _GUICtrlListView_AddColumn($cListView, "CTR") _GUICtrlListView_AddColumn($cListView, "eCPM") _GUICtrlListView_AddColumn($cListView, "Earnings", 80) For $i = 0 To 3 GUICtrlCreateListViewItem($aData[$i], $cListView) Next GUISetState() Global $iCol While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cListView $iCol = GUICtrlGetState($cListView) _GUICtrlListView_SimpleSort($cListView, $fSortSense, $iCol) EndSwitch WEnd telmob and Ambient 1 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 10, 2014 Moderators Share Posted March 10, 2014 BrewManNH,I keep forgetting that you can do it that way! 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...
BrewManNH Posted March 10, 2014 Share Posted March 10, 2014 I'm infinitely lazy, I only like to type as much/little as possible to achieve my objective. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Jack023 Posted March 10, 2014 Author Share Posted March 10, 2014 Well done, it's working right now ! Link to comment Share on other sites More sharing options...
OneJeremias Posted April 11, 2014 Share Posted April 11, 2014 Might someone take a look at my code and tell me why it's not sorting? Nothing happens when I click the column header, although I do believe I have implemented BrewMan's code correctly. I'm wondering if it has anything to do with the data I pull from the excel spreadsheet...can anything from that process cause problems with sorting this way? Thanks for any help: expandcollapse popup#include <Excel.au3> #include <Array.au3> #include <GuiImageList.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Global $fSortSense = False ; Set initial ascending sort $oExcel = _ExcelBookOpen("c:\users.xls", @SW_HIDE) _ExcelSheetActivate($oExcel, "Sheet1") $result = _ExcelReadSheetToArray($oExcel) _ExcelBookClose($oExcel) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 986, 581, 192, 124) $hListView = _GUICtrlListView_Create($Form1, "Computer name|User|Dept|Location", 20, 15, 500, 170) ; create the list view _GUICtrlListView_SetColumnWidth($hListView, 0, 100) _GUICtrlListView_SetColumnWidth($hListView, 1, 175) _GUICtrlListView_SetColumnWidth($hListView, 2, 130) _GUICtrlListView_SetColumnWidth($hListView, 4, 50) _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT ) ; selecting one item highlights entire row $Button1 = GUICtrlCreateButton("Ninite", 525, 56, 89, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### for $i = 0 to UBound($result,1) - 3 _GUICtrlListView_AddItem($hListView, $result[$i + 2][1], 0) _GUICtrlListView_AddSubItem ($hListView, $i, $result[$i + 2][2], 1) _GUICtrlListView_AddSubItem ($hListView, $i, $result[$i + 2][3], 2) _GUICtrlListView_AddSubItem ($hListView, $i, $result[$i + 2][4], 3) ;Sleep(2000) Next GUISetState() Global $iCol While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $hListView $iCol = GUICtrlGetState($hListView) _GUICtrlListView_SimpleSort($hListView, $fSortSense, $iCol) EndSwitch WEnd Link to comment Share on other sites More sharing options...
BrewManNH Posted April 11, 2014 Share Posted April 11, 2014 GUIGetMsg won't work with control handles, and the listview was created using the UDF and not the native functions. If you create your listview with the native function it should work. $hListView = GUICtrlCreateListView("Computer name|User|Dept|Location", 20, 15, 500, 170) ; create the list view If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
OneJeremias Posted April 15, 2014 Share Posted April 15, 2014 Ok great, that worked! However, I'm not entirely clear on why. When I switched to using a native function, what does that mean in terms of what GUIGetMsg is receiving? It is not getting a control handle anymore? I believe I have a [very] incomplete understanding of how all the pieces work together, so please excuse me if my code indicates that I'm farther along than I actually am :-) Link to comment Share on other sites More sharing options...
BrewManNH Posted April 15, 2014 Share Posted April 15, 2014 GUIGetMsg works with the control IDs that AutoIt's native functions return, and with the handle from the GUICreate function. It will not work with the handles returned by the UDF functions which is why your script wouldn't work when you used _GUICtrlListView_Create to create the listview. You can get the handle from a control ID using GUICtrlGetHandle, but you can't get the control ID from the handle because there isn't one. The built-in functions in AutoIt will usually only work with control IDs returned from AutoIt built-in functions. The UDFs will most of the time work with either, although some of them don't work 100% accurately with a control ID. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
OneJeremias Posted April 16, 2014 Share Posted April 16, 2014 Ok that makes sense. Thank you for the help! On to the next piece of this project which will inevitably send me back here :-) 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