Jump to content

Sort items in a ListView


Recommended Posts

I have tried to read other topics about it, but I don't understand how do it. I have a listview with 3 columns (software, version, update) and n lines (one per application) and I need to sort its items (they are added with "_GUICtrlListView_AddItem" and for each item is set also a parameter).

Firstly I need to sort all items (keeping subitems synchronized) in alphabetical order of the first column items. Then I need also to allow to order items (always keeping subitems synchronized) clicking on column headers.

I have tried with "_GUICtrlListView_SimpleSort($hListView, $B_DESCENDING, 0)", but it cause some bugs: doesn't keep parameters synchronized with items and remove the ".0" from versions like "1.0", "2.0" of apps (I think because sorting version column, it convert strings in integer if are read as numbers).

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

I have tried to read other topics about it, but I don't understand how do it. I have a listview with 3 columns (software, version, update) and n lines (one per application) and I need to sort its items (they are added with "_GUICtrlListView_AddItem" and for each item is set also a parameter).

Firstly I need to sort all items (keeping subitems synchronized) in alphabetical order of the first column items. Then I need also to allow to order items (always keeping subitems synchronized) clicking on column headers.

I have tried with "_GUICtrlListView_SimpleSort($hListView, $B_DESCENDING, 0)", but it cause some bugs: doesn't keep parameters synchronized with items and remove the ".0" from versions like "1.0", "2.0" of apps (I think because sorting version column, it convert strings in integer if are read as numbers).

Doing this search yielded this post that contains this code:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

GUICreate("ListView Add SubItem", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, $LVS_EX_FULLROWSELECT)
GUISetState()


; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)

_GUICtrlListView_RegisterSortCallBack($hListView)

; Add items
_GUICtrlListView_AddItem($hListView, "a", 0, _GUICtrlListView_GetItemCount($hListView) + 9999)
_GUICtrlListView_AddSubItem($hListView, 0, "1", 1, 1)

_GUICtrlListView_AddItem($hListView, "b", 1, _GUICtrlListView_GetItemCount($hListView) + 9999)
_GUICtrlListView_AddSubItem($hListView, 1, "3", 1, 1)

_GUICtrlListView_AddItem($hListView, "c", 1, _GUICtrlListView_GetItemCount($hListView) + 9999)
_GUICtrlListView_AddSubItem($hListView, 2, "2", 1, 1)


ToolTip("NOT SORTED")
Sleep(2000)
_GUICtrlListView_SortItems($hListview, 1); sorts the entire listview based off the column with index 1 (the second one)
ToolTip("SORTED")

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Does that help?

Link to comment
Share on other sites

Yes, it help me.. but it doesn't work fine. I saw that it sort only items with the same parameter. I create items with this code:

$item = _GUICtrlListView_AddItem($hListView, $file, -1, $param)

and the parameter is 0, 1 or 2 (depend on source directory).

In this screenshot you can see that it firstly makes group by parameter (shown in the last column) and then sort by name:

Posted Image

Edited by Lupo73

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

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...