Jump to content

[SOLVED]]Listview repopulate is slow


Montfrooij
 Share

Recommended Posts

Hello,

I've got a problem with repopulating listviews.

The initial population is done without delay, but the repopulating takes a moment.

I've added a simplified script that shows what I mean:

  • Click 'Start' and you will see the GUI with the listview being generated (fast),
  • Click 'Repopulate' and you will see the listview being repopulated (slower).

Both populations of the listview are done the same way (as far as I can tell) ;)

How can I make the repopulate action faster?

Thanks in advance.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Global $hListView, $hListView2,$bRepop,$bStart

    GUICreate("Start", 300, 50)
    $bStart = GUICtrlCreateButton("Start", 10, 10, 280, 25)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $bStart
                _Example1()

        EndSwitch
    WEnd


Func _Example1() ;GUI with listview

    Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
    Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)

    GUICreate("ListView Sort", 300, 300)
    $bRepop = GUICtrlCreateButton("Repopulate", 10, 270, 280, 25)

    $hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 260, -1, $iExWindowStyle)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)

    For $r = 1 To 1000
        GUICtrlCreateListViewItem($r & "|" & random(0,90) &"|" & random(0,90),$hListView)
        GUICtrlSetBkColor(-1, 0xD0DEC7)
    Next

    MsgBox(0,"","Ready")

    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))
            Case $bRepop
                _Repop()

        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($hListView)
    GUIDelete()
EndFunc   ;==>_Example1


Func _Repop()
_GUICtrlListView_DeleteAllItems($hListView)
        For $r = 1 To 1000
        GUICtrlCreateListViewItem($r & "|" & random(0,90) &"|" & random(0,90),$hListView)
        GUICtrlSetBkColor(-1, 0xD0DEC7)
    Next

MsgBox(0,"","Ready")

EndFunc

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $hWndListView2

    $hWndListView = $hListView
    $hWndListView2 = $hListView2
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    If Not IsHWnd($hListView2) Then $hWndListView2 = GUICtrlGetHandle($hListView2)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView, $hWndListView2
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)

                    ; Kick off the sort callback
                    _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
                    ; No return value
            EndSwitch
    EndSwitch
    Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY
Edited by Montfrooij
Link to comment
Share on other sites

...

Dim $aItem[1000]

...

Func _Example1()

    ...

    For $r = 1 To 1000
        $aItem[$r - 1] = GUICtrlCreateListViewItem($r & "|" & Random(0, 90) & "|" & Random(0, 90), $hListView)
        GUICtrlSetBkColor(-1, 0xD0DEC7)
    Next

    MsgBox(0, "", "Ready")

    ...
    
EndFunc   ;==>_Example1

Func _Repop()
    For $r = 1 To 1000
        GUICtrlSetData($aItem[$r - 1], $r & "|" & Random(0, 90) & "|" & Random(0, 90))
    Next
    MsgBox(0, "", "Ready")
EndFunc   ;==>_Repop

...

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