Sign in to follow this  
Followers 0
JusGellin

ListView Sort

8 posts in this topic

How can I sort as shown below after I load a listview from a file? I tried following the example except I'm loading a full file in instead. This doesn't work. Thanks.

#include <GuiConstantsEx.au3>
 #include <GuiListView.au3>
 #include<File.au3>
 
 $Gui = GUICreate("Test", 300, 200)
 $hListView = GUICtrlCreateListView("Items|SubItems", 2, 2, 296, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
 _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
 
 GUISetState()
 
;~ getLVitems()
;Dim $File_Array
 Dim $temp
 $File = "D:\Index\Utilities\Autoit\Scripts\test.txt"
 _FileReadToArray($File, $temp)
 
 $no = $temp[0] - 1
 Dim $result[$no][2]
 
 For $x = 1 To $no
     $t = StringSplit($temp[$x], ",")
     $result[$x - 1][0] = $t[1]
     $result[$x - 1][1] = $t[2]
 Next
 
 _GUICtrlListView_AddArray($hListView, $result)
 _GUICtrlListView_RegisterSortCallBack($hListView)
 
 While 1
     Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
             ExitLoop
         Case $hListView
             _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
     EndSwitch
 WEnd

Here's some of Text.txt contents:

Item1,44
 Item2,22
 Item1,11
 Item2,33
 Item3,
 Item1,
 Item2,
 Item3,
 Item1,

Share this post


Link to post
Share on other sites



$LVS_SORTASCENDING OR $LVS_SORTDESCENDING


Triton

Share this post


Link to post
Share on other sites

$LVS_SORTASCENDING OR $LVS_SORTDESCENDING

That didn't help. It still doesn't sort.

Share this post


Link to post
Share on other sites

Try

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <WindowsConstants.au3>

$Gui = GUICreate("Test", 300, 200)
$hListView = GUICtrlCreateListView("Items|SubItems", 2, 2, 296, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER ))

Dim $aFile
$File = "D:\Index\Utilities\Autoit\Scripts\test.txt"
_FileReadToArray($File, $aFile)

$iSize = $aFile[0]
Dim $result[$iSize][2]

For $x = 1 To $iSize
    $aCol = StringSplit($aFile[$x], ",")
    $iIndex = _GUICtrlListView_AddItem($hListView, $aCol[1], -1, $x)
    For $y = 2 To $aCol[0]
        _GUICtrlListView_AddSubItem($hListView, $iIndex, $aCol[$y], $y - 1)
    Next
Next
GUISetState()

_GUICtrlListView_RegisterSortCallBack($hListView)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hListView
        ; Kick off the sort callback
            _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
    EndSwitch
WEnd
_GUICtrlListView_UnRegisterSortCallBack($hListView)
GUIDelete()

Share this post


Link to post
Share on other sites

Try

That works, thanks. Is that because the listview must be populated line by line and just adding an array doesn't work with the sort?

Share this post


Link to post
Share on other sites

That works, thanks. Is that because the listview must be populated line by line and just adding an array doesn't work with the sort?

Yes, it appears for sort to work using _GUICtrlListView_RegisterSortCallBack requires _GUICtrlListView_AddItem to have a value in $iParam. I normally use _GUICtrlListView_SimpleSort.

Share this post


Link to post
Share on other sites

Yes, it appears for sort to work using _GUICtrlListView_RegisterSortCallBack requires _GUICtrlListView_AddItem to have a value in $iParam. I normally use _GUICtrlListView_SimpleSort.

Thanks for the explanation and the tip.

Share this post


Link to post
Share on other sites

_GUICtrlListView_SortItems() and _GUICtrlListView_RegisterSortCallBack() don't work with _GUICtrlListView_AddArray()... good to know :) (just to add some keywords)...

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