JusGellin Posted September 14, 2008 Share Posted September 14, 2008 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, Link to comment Share on other sites More sharing options...
Triton Posted September 14, 2008 Share Posted September 14, 2008 $LVS_SORTASCENDING OR $LVS_SORTDESCENDING Triton Link to comment Share on other sites More sharing options...
JusGellin Posted September 14, 2008 Author Share Posted September 14, 2008 $LVS_SORTASCENDING OR $LVS_SORTDESCENDINGThat didn't help. It still doesn't sort. Link to comment Share on other sites More sharing options...
picaxe Posted September 15, 2008 Share Posted September 15, 2008 Try expandcollapse popup#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() Link to comment Share on other sites More sharing options...
JusGellin Posted September 15, 2008 Author Share Posted September 15, 2008 TryThat works, thanks. Is that because the listview must be populated line by line and just adding an array doesn't work with the sort? Link to comment Share on other sites More sharing options...
picaxe Posted September 15, 2008 Share Posted September 15, 2008 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. Link to comment Share on other sites More sharing options...
JusGellin Posted September 15, 2008 Author Share Posted September 15, 2008 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. Link to comment Share on other sites More sharing options...
KaFu Posted October 30, 2009 Share Posted October 30, 2009 _GUICtrlListView_SortItems() and _GUICtrlListView_RegisterSortCallBack() don't work with _GUICtrlListView_AddArray()... good to know (just to add some keywords)... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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