Sontec Posted January 4, 2012 Share Posted January 4, 2012 I have a Listviewcontrol and I use _GUICtrlListView_SortItems to sort the items therein, however the items are only sorted when I click the column. I have had a look at the _GUICtrlListView_SimpleSort function but found the example to difficult with al those DllStructGetData and megazillion handles. I would like the Listview to be sort ascending on column 0 by default and also know if a the sortstatus of the ListView is ascending or descending. Is this possible? Link to comment Share on other sites More sharing options...
BrewManNH Posted January 4, 2012 Share Posted January 4, 2012 If you call the function to sort the listview, you don't need to click the column to do that, just call the function somewhere in your script after everything is put into the listview, or sort the items before you put them into your listview. If you put all of the listview items into an array first, you can use _ArraySort to sort the array, and then add the array to the LV. 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 January 4, 2012 Moderators Share Posted January 4, 2012 Sontec,Welcome to the Autoit forum. You can easily sort a ListView using _GUICtrlListView_SimpleSort - but you need to take care how you do it. Here is a short example:expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> Global $fSortDescending = False Global $aNames[10] = ["Fred","Tom", "Dick", "Harry", "Peter", "Paul", "Mary", "Alice", "Bob", "Eve"] $hGUI = GUICreate("Test", 500, 500) $hListView = GUICtrlCreateListView("Names", 10, 10, 300, 300) For $i = 0 To 9 GUICtrlCreateListViewItem($aNames[$i], $hListView) Next $hButton = GUICtrlCreateButton("Sort", 10, 400, 80, 30) $hLabel = GUICtrlCreateLabel("", 100, 405, 200, 20) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton ; Sort column 0 _GUICtrlListView_SimpleSort($hListView, $fSortDescending, 0) Switch $fSortDescending Case True GUICtrlSetData($hLabel, "Sorted Descending") Case Else GUICtrlSetData($hLabel, "Sorted Ascending") EndSwitch EndSwitch WEndThe trick is the $fSortDescending variable so that the function knows which way to sort each time. M23 232showtime 1 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...
Sontec Posted January 5, 2012 Author Share Posted January 5, 2012 For now I used BrewManNH suggestion to pre-sort my array and then add it to the ViewList.In the (near) future I am gonna try to use the SimpleSort, the example provided by Melba23 is slightly simpler and more understandable than the one in the AutoIt-helpfile ;-)Thanks both for your help and suggestions.Best regards,Martijn (Sontec) 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