Jump to content

_GUICtrlListView_SimpleSort() (GUIOnEventMode)


dRsrb
 Share

Recommended Posts

Hi! :)

I have a few problems regarding sorting a list.

As I haven't found any examples that deal with sorting in "GUIOnEventMode" I have big problems to implement it in my app.

I read a lot of threads, but all solutions deal with MessageLoop mode. I probably had never choose OnEvent mode. Hmmm... It's my 1st AutoIt app.

As you can see in the example, the items of the list aren't sorted just once. The function "_ListViewSort()" is invoked several times (seemingly once for every item in the list). I mean that with dancing.

The next thing I noticed is that some items disappear (replaced by other)! Just compare the code with your result after sorting the list for several times.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

#include <EditConstants.au3>

AutoItSetOption('GUIOnEventMode', 1)
AutoItSetOption('MustDeclareVars', 1)

Global Const $ApplicationTitle = 'Test'
Global $Main
Global $ListView

_Main()

Func _Main()
    
    $Main = GUICreate($ApplicationTitle, 88, 186, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_ExitApplication')
    
    $ListView = GUICtrlCreateListView('Text', 0, 0, 88, 186, $ES_READONLY)
    _GUICtrlListView_SetExtendedListViewStyle($ListView, $LVS_EX_INFOTIP)
    _GUICtrlListView_SetColumnWidth($ListView, 0, 66)
    GUICtrlRegisterListViewSort($ListView, '_ListViewSort')

    _GUICtrlListView_RegisterSortCallBack($ListView)
    
    _TestFunc_SetItem()
    
    GUISetState(@SW_SHOW)
    
    While True
        Sleep(1000)
    WEnd
    
EndFunc

Func _ExitApplication()

    If @GUI_WINHANDLE = $Main Then
        Exit 0
    EndIf
    
EndFunc

Func _TestFunc_SetItem()
    
    GUICtrlCreateListViewItem('Test1', $ListView)
    GUICtrlCreateListViewItem('Test2', $ListView)
    GUICtrlCreateListViewItem('Test3', $ListView)
    GUICtrlCreateListViewItem('TEST1', $ListView)
    GUICtrlCreateListViewItem('TEST2', $ListView)
    GUICtrlCreateListViewItem('TEST3', $ListView)
    GUICtrlCreateListViewItem('Entry1', $ListView)
    GUICtrlCreateListViewItem('Entry2', $ListView)
    GUICtrlCreateListViewItem('Entry3', $ListView)
    
EndFunc

Func _ListViewSort()
    
    _GUICtrlListView_SortItems($ListView, GUICtrlGetState($ListView))
    
EndFunc

Where is my error in reasoning? Should I rewrite my app to work in MessageLoop mode? Hmm... I'm very confused.

EDIT:

Just realized: It's the wrong forum. Sorry.

Edited by dRsrb
Link to comment
Share on other sites

  • 2 weeks later...

I would appreciate a solution too. I didnt had to do much with Listview sorting and Callback is still a bit over my MSDN knowledge.

But i can guess that you either have to work with:

  • GUICtrlRegisterListViewSort and use the internal LV functions (GUICtrlCreateListViewItem) for creating Items

OR

  • _GUICtrlListView_RegisterSortCallBack($ListView) with the new UDF functions (_GUICtrlListView_AddItem)

    and use GUICtrlSetOnEvent($ListView,"_ListViewSort") to call a function with _GUICtrlListView_SortItems

The second Listview is just for demonstrating the option with GUICtrlRegisterListViewSort. normally there is a real sorting script inside the _ListViewSort function. Here just the order of the items are being switched.

On the first LV i came so far that the arrows become visible and change but no sorting takes place.

I believe the trick lays in the way callback works in OnEventMode.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

#include <WindowsConstants.au3>

AutoItSetOption('GUIOnEventMode', 1)
;~ AutoItSetOption('MustDeclareVars', 1)

Global Const $ApplicationTitle = 'Test'
Global $Main
Global $ListView

_Main()

Func _Main()
    
    $Main = GUICreate($ApplicationTitle, 404, 186, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_ExitApplication')
    
    
    

    $ListView = GUICtrlCreateListView('Text', 0, 0, 200, 186,-1)
    $ListView2 = GUICtrlCreateListView('Text', 202, 0, 200, 186,-1)
    
    _GUICtrlListView_AddColumn($ListView , "0")
    _GUICtrlListView_AddColumn($ListView , "1")
    _GUICtrlListView_AddColumn($ListView , "2")
    _GUICtrlListView_AddColumn($ListView , "3")
    _GUICtrlListView_AddColumn($ListView2 , "0")
    _GUICtrlListView_AddColumn($ListView2 , "1")
    _GUICtrlListView_AddColumn($ListView2 , "2")
    _GUICtrlListView_AddColumn($ListView2 , "3")
    _TestFunc_SetItem($ListView)
    _TestFunc_SetItem($ListView2)
    
    GUICtrlSetOnEvent($ListView,"_ListViewSort")
    _GUICtrlListView_RegisterSortCallBack($ListView)
    
    GUICtrlRegisterListViewSort($ListView2, '_ListViewSort2')

   
;~     GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
    GUISetState(@SW_SHOW)
    
    While True
        Sleep(1000)
    WEnd
    
EndFunc

Func _ExitApplication()
    _GUICtrlListView_UnRegisterSortCallBack($ListView)
    If @GUI_WINHANDLE = $Main Then
        Exit 0
    EndIf
    
EndFunc

Func _TestFunc_SetItem($iLV)
    For $i = 0 To 5
        $iInde = _GUICtrlListView_AddItem($iLV, "test"&$i)
         _GUICtrlListView_SetColumnWidth($iLV, 0, $LVSCW_AUTOSIZE_USEHEADER)
        For $x = 1 To 3
            _GUICtrlListView_AddSubItem($iLV, $iInde, Random(0,9,1)&Chr(Random(97,122,1))&"hmm", $x)
            _GUICtrlListView_SetColumnWidth($iLV, $x , $LVSCW_AUTOSIZE)
        Next
    next
EndFunc

Func _ListViewSort()
    Local $icol = GUICtrlGetState($ListView)
 ConsoleWrite("sorting col: "&$icol & @CRLF)
 _GUICtrlListView_SortItems($ListView, $icol)
EndFunc

Func _ListViewSort2()
;   Return value Meaning 
;   -1 1st item should precede the 2nd. 
;   0 No Change. 
;   1 1st item should follow the 2nd. 
    Return 1
EndFunc
Edited by qsek
Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
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...