Jump to content

ListView sorting and Index column

Recommended Posts

Hi all,

Below code is an example (borrowed from randallc and slightly modified). What I would like is to sort all columns except the index column. Currently when you try sorting, all the columns get sorted which is fine but looks ugly if you have one of the columns simply being an "index" column.

Below is the code:

#include <GuiConstants.au3>
#include <GuiListView.au3>

$searchGUI = GUICreate("ListView Sort", 810, 623, (@DesktopWidth - 800) / 2, (@DesktopHeight - 600) / 2,$WS_MAXIMIZEBOX  + $WS_MINIMIZEBOX)

$listview = GUICtrlCreateListView("Index|Student|Marks", 10, 10, 790, 530, -1, BitOR($LVS_EX_REGIONAL, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

for $i=1 to 40
    $s_RandomListItem=$i &"|"&Random(-10000, 10000, 1)&"|more_"&Chr(Random(Asc("a"), Asc("z"), 1))&Chr(Random(Asc("a"), Asc("z"), 1))&String(Random(-10000, 10000, 1))

    GUICtrlCreateListViewItem($s_RandomListItem, $listview)

_GUICtrlListViewSetColumnWidth ($listview, 0, 100)
_GUICtrlListViewSetColumnWidth ($listview, 1, 200)
_GUICtrlListViewSetColumnWidth ($listview, 2, 100)


Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview) ]

While 1
    $msg = GUIGetMsg()
            Case $msg = $GUI_EVENT_CLOSE
            Case $msg = $listview
        ; sort the list by the column header clicked on
            _GUICtrlListViewSort($listview, $B_DESCENDING, GUICtrlGetState($listview))

My suggestion was to re-sort just the "index" column after the regular sorting has completed. For example:

_GUICtrlListViewSort($listview, $B_DESCENDING, GUICtrlGetState($listview))
For $i=1 to 40
    GUICtrlCreateListViewItem($i & "|" & "" & "|" & "", $listview)

This obviously doesn't work. I thought another idea:

_GUICtrlListViewSort($listview, $B_DESCENDING, "all columns but index column")

But I don't know the right syntax for this idea.

I have searched the forums and haven't seen any requests of this nature. Does anyone know how to do it? Any help is appreciated :D


Link to post
Share on other sites


Fun, but wouldn't you want to keep the index?

Case $msg = $listview
                ; sort the list by the column header clicked on
                _GUICtrlListViewSort($listview, $B_DESCENDING, GUICtrlGetState($listview))
                _GUICtrlListViewInsertColumn ($listview, 0, "Index")
                For $i=0 to 40-1
                    $s_Item=_GUICtrlListViewGetItemText ($listview,$i,-1)
                    ;MsgBox(0,"","$i&_GUICtrlListViewGetItemText ($listview)="&$s_Item)
Best, Randall
Link to post
Share on other sites

Hi randallc,

Thanks for helping out. In response to your question, yes I do want the index column, however I think that after sorting, it doesn't look good, thats why I was looking to sort it.

Bytheway I have implemented your _GUICtrlListView.au3 replacing the default GuiListView.au3 and am very impressed with it. Undoubtedly faster in sorting and with the bonus that it doesn't have a limitation of entries in the ListView. Keep it up! :D

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...