PaulBaumann Posted August 30, 2014 Posted August 30, 2014 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
BrewManNH Posted August 30, 2014 Posted August 30, 2014 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 GudeHow 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
Zedna Posted August 30, 2014 Posted August 30, 2014 (edited) Look here Edited August 30, 2014 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
PaulBaumann Posted August 31, 2014 Author Posted August 31, 2014 (edited) 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 August 31, 2014 by PaulBaumann
Moderators Melba23 Posted August 31, 2014 Moderators Posted August 31, 2014 (edited) 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?). M23Edit:Proof of concept: expandcollapse popup#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_NOTIFYSecond edit:You can tell it is early - my GUIListViewEx UDF already does this for you! Take a look at the _GUIListViewEx_ReturnArray function. Edited August 31, 2014 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
PaulBaumann Posted August 31, 2014 Author Posted August 31, 2014 (edited) 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 August 31, 2014 by PaulBaumann
Moderators Melba23 Posted August 31, 2014 Moderators Posted August 31, 2014 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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Pbaumann Posted September 11, 2014 Posted September 11, 2014 BTW: LVM_Checked and LVM_Unchecked are not included in ListViewConstants.au3. I think it would be helpful adding them to this include. Any chance of integration? Best wishes Paul
BrewManNH Posted September 11, 2014 Posted September 11, 2014 (edited) 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 September 11, 2014 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 GudeHow 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
Moderators Melba23 Posted September 11, 2014 Moderators Posted September 11, 2014 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! 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now