Sign in to follow this  
Followers 0
dash007

ListView sorting and Index column

4 posts in this topic

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)
next

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

GUISetState()

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview) ]

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

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)
Next

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

Cheers

Share this post


Link to post
Share on other sites



Hi,

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")
                _GUICtrlListViewDeleteColumn($listview,0)
                For $i=0 to 40-1
                    $s_Item=_GUICtrlListViewGetItemText ($listview,$i,-1)
                    ;MsgBox(0,"","$i&_GUICtrlListViewGetItemText ($listview)="&$s_Item)
                    _GUICtrlListViewDeleteItem($listview,$i)
                    _GUICtrlListViewInsertItem($listview,$i,($i+1)&"|"&$s_Item)
                Next
Best, Randall

Share this post


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

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