Jump to content

Default Sort for ListViewcontrol and SortStatus


 Share

Recommended Posts

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

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 Gude
How 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

  • Moderators

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:

#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

WEnd

The trick is the $fSortDescending variable so that the function knows which way to sort each time. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...