Jump to content

Evaluating Listview is slow


Recommended Posts

I've created a listview with checkboxes.

At some point in my program all checked items have to be processed. To get the checked items I'm looping through the listview:

    For $i = 0 To _GUICtrlListView_GetItemCount($hLV) - 1
        If _GUICtrlListView_GetItemChecked($hLV, $i) Then
            SQLCheckUpd( _
                    _GUICtrlListView_GetItemText($hLV, $i, $eFname), _
                    _GUICtrlListView_GetItemText($hLV, $i, $eCheckakt), _
                    _GUICtrlListView_GetItemText($hLV, $i, $eScandate))
        EndIf
    Next

This works fine, but with a larger number of elements it's very slow.

Is there another (faster) way to get all checked items (or their indices) of a listview?

Best wishes
Paul

Link to comment
Share on other sites

I've never found a faster way of doing it. I don't know if it's faster to use the AutoIt control ID or the ListView handle, but if you're using GUICtrlCreateListview and not _GUICtrlListview_Create you can try it both ways.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thank for reply.

As far a I can  see there's no function to get something like a collection of checked elements. So looping through all items can't be eliminated.

Using "optimized" (less error control, more specific to this task) functions instead of the UDF functions with all their bells and whistles, seem to be the only way to improve performance.

Best wishes

Paul

Edited by PaulBaumann
Link to comment
Share on other sites

  • Moderators

PaulBaumann,

Perhaps you could track the ListView items in a separate array as they are checked/unchecked - that way you would have the current state ready to use and not have to loop through the ListView each time. I seem to remember that you need to register one of the WM_NOTIFY messages (ITEMCHANGED?). :)

M23

Edit:

Proof of concept: :)

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <Array.au3>

Global Const $LVM_CHECKED = 8192, $LVM_UNCHECKED = 4096

Local $hGUI = GUICreate("MyGUI", 500, 500)

Global $cLV = GUICtrlCreateListView("Column1|Column2", 10, 10, 480, 250, Default)
_GUICtrlListView_SetExtendedListViewStyle($cLV, $LVS_EX_CHECKBOXES)

For $i = 0 To 9
    GUICtrlCreateListViewItem("Item " & $i, $cLV)
Next

$cRead = GUICtrlCreateButton("Read", 10, 300, 80, 30)

GUISetState(@SW_SHOW, $hGUI)

Global $aCheckedArray[_GUICtrlListView_GetItemCount($cLV)]

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $cRead
            _ArrayDisplay($aCheckedArray, "", Default, 8)
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $iIDFrom = 0, $iCode = 0, $tNMHDR = 0, $tInfo = 0

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)

    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $cLV
            Switch $iCode
                Case $LVN_ITEMCHANGED
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    $iItem = DllStructGetData($tInfo, "Item")
                    $iNewState = DllStructGetData($tInfo, "NewState")
                    Switch $iNewState
                        Case $LVM_CHECKED
                            $aCheckedArray[$iItem] = 1
                        Case $LVM_UNCHECKED
                            $aCheckedArray[$iItem] = 0
                    EndSwitch
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY
Second edit:

You can tell it is early - my GUIListViewEx UDF already does this for you! Take a look at the _GUIListViewEx_ReturnArray function. :D

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Perhaps you could track the ListView items in a separate array as they are checked/unchecked - that way you would have the current state ready to use and not have to loop through the ListView each time. I seem to remember that you need to register one of the WM_NOTIFY messages (ITEMCHANGED?). :)

 

Hi,

thanks for this tip. This will be the best solution for my needs. My listview normally contains even more unchecked as checked items, so this will will be a major improvement. Thanks for the proof of concept, after integrating this logic into my program the performance was boosted :-)

 

Regarding _GUIListViewEx_ReturnArray I seem to miss something. I took a look at the code and found this:

...
            Local $aCheck_Array[UBound($aRetArray)]

            For $i = 1 To UBound($aRetArray) - 1
                $aCheck_Array[$i] = _GUICtrlListView_GetItemChecked($aGLVEx_Data[$iIndex][0], $i - 1)
            Next

For me it looked as you are also looping through the whole listview to identify the checked items. Did I miss something?

 

Best wishes

Paul

PS: anyone who will also use this method should take in account that the itemnumber changes when the listview is sorted. You should sort your array according to the the listview...

Edited by PaulBaumann
Link to comment
Share on other sites

  • Moderators

PaulBaumann,

No, that is exactly what the UDF does - it was just that I came up with the idea and only then realised that the UDF did much the same sort of thing. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 weeks later...

What are those 2 values (LVM_Checked and LVM_Unchecked) set to?

MSDN doesn't list them, and I can only find 3 references to them that's posted in 3 1 year old threads on this forum. I googled LVM_CHECKED Listview and that's all that shows up.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

Pbaumann,

They are not standard MS constants as far as I can see - MSDN does not mention them at all and certainly not as the "NewState" value of a NMLISTVIEW. In fact the only references that Google finds are from this forum! :wacko:

I got the both the names and the values from a posted script which I had saved in my Snippets folder. Unless someone can give us a reference explaining their origin I do not see how we can add them. :(>

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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