Sign in to follow this  
Followers 0
pshankland

Help with sorting columns (_GUICtrlListViewSort)

5 posts in this topic

I have the following script and want to sort the columns when you click on them. I have read through the help files and it seems as though I need to use the _GUICtrlListViewSort function, but to be honest I am stuck with knowing how to include it within my script:

#include <Include\GUIConstants.au3>
#include <Include\GUIListView.au3>

GUICreate("Software Audit", 700, 335, 193, 115)
$ListView = GUICtrlCreateListView("DisplayName|RegKey", -1, -1, 700, 260,"",BitOR($LVS_SORTASCENDING,$LVS_EX_GRIDLINES))
$Button1 = GUICtrlCreateButton("Get list", 16, 288, 225, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _getList()
    EndSwitch
WEnd

Func _getList()
    $i = 1
    $listItems = ''
    Do
        $SoftwareKey = RegEnumKey("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
        If @error <> 0 Then ExitLoop
        $DisplayName = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $SoftwareKey, "DisplayName")
        If $DisplayName = "" Then $DisplayName = "****"
        GUICtrlCreateListViewItem($DisplayName & "|" & $SoftwareKey, $ListView)
        $i = $i + 1
    Until 0
EndFunc

Would really appreciate any help with this one.

Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

It may also be worth pointing out that I have just discovered that I am having a problem with the standard GUIListView.au3 include anyway as am getting the following error when I just include it:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "E:\Scripts\list2.au3"

E:\Scripts\Include\GUIListView.au3 (102) : ==> Duplicate function name.:

Func _GUICtrlListViewCopyItems($h_Source_listview, $h_Destination_listview, $i_DelFlag = 0)

>Exit code: 1 Time: 0.717

Any ideas?

Edited by pshankland

Share this post


Link to post
Share on other sites

It may also be worth pointing out that I have just discovered that I am having a problem with the standard GUIListView.au3 include anyway as am getting the following error when I just include it:

Any ideas?

Then you must have the functions included twice, which is difficult because GUiListView has "#include-once" on the first line.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Then you must have the functions included twice, which is difficult because GUiListView has "#include-once" on the first line.

Have changed #include <Include\GUIListView.au3> to #include <GUIListView.au3> and that error has dissapeared.

Still can't seem to get my head around how to get the columns sorted though....

Share this post


Link to post
Share on other sites

Still can't seem to get my head around how to get the columns sorted though....

Simple sort code snippet. Search forum and helpfile for GUICtrlRegisterListViewSort

GUICtrlRegisterListViewSort($ListView1, "LVSort")

Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
    If $nColumn = 0 Then
        $val1 = GetSubItemText($ListView1, $nItem1, $nColumn)
        $val2 = GetSubItemText($ListView1, $nItem2, $nColumn)
        
        $nResult = 0 ; No change of item1 and item2 positions

        If $val1 < $val2 Then
            $nResult = -1  ; Put item2 before item1
        ElseIf  $val1 > $val2 Then
            $nResult = 1   ; Put item2 behind item1
        EndIf
        
        Return $nResult
    Else 
        Return 0 ; No change of item1 and item2 positions
    EndIf
EndFunc

Share this post


Link to post
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
Sign in to follow this  
Followers 0