egridley Posted April 13, 2012 Share Posted April 13, 2012 I am having trouble with duplicate ControlID. I have created a GUI with a ListView inside of it. However, some of the items in the list view are conflicting with the buttons that I have on the GUI. For example, if I click on the File12, it has the same ControlID as the column header, and so it sorts the column. If I click on File15, it has the same ControlID as the Refresh button. I'm sure it's something simple that I'm doing wrong, but any help would be appreciated. This is the most complex GUI I have ever done, so be patient with me! Here is the code I am using: expandcollapse popupOpt("TrayIconDebug",1) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListviewConstants.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <Array.au3> #include <File.au3> ; Script Start - Add your code below here Main() Func Main() Global $ColumnHeaders[9] = [8,"Title","Type","Video","Audio","Processing","Completed","Percent","Status"] Global $RefreshTime = 0 Local $wWidth = 800 Local $wHeight = 500 Local $iWindowStyle = BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SYSMENU, $WS_MINIMIZEBOX) Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Local $iListViewStyle = BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_REPORT) Local $iExListViewStyle = BitOR($LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_HEADERDRAGDROP) $MainGUI = GUICreate("File Monitor", $wWidth, $wHeight, 150, 150, $iWindowStyle, $iExWindowStyle) GUISetBkColor(0x94AAFF) ; will change background color Global $NotReadyCheckbox = GUICtrlCreateCheckbox("Not Ready: ",150,20) GUICtrlSetResizing(-1,802) GUICtrlSetState(-1,$GUI_CHECKED) Global $NotReadyLabel = GUICtrlCreateLabel(0,228,22,30) GUICtrlSetResizing(-1,802) GUICtrlSetFont(-1,12) GUICtrlSetColor(-1,0x0000FF) Global $ReadyCheckbox = GUICtrlCreateCheckbox("Ready: ",280,20) GUICtrlSetResizing(-1,802) GUICtrlSetState(-1,$GUI_CHECKED) Global $ReadyLabel = GUICtrlCreateLabel(0,338,22,30) GUICtrlSetResizing(-1,802) GUICtrlSetFont(-1,12) GUICtrlSetColor(-1,0x0000FF) Global $ProcessingCheckbox = GUICtrlCreateCheckbox("Processing: ",400,20) GUICtrlSetResizing(-1,802) GUICtrlSetState(-1,1) Global $ProcessingLabel = GUICtrlCreateLabel(0,479,22,30) GUICtrlSetResizing(-1,802) GUICtrlSetFont(-1,12) GUICtrlSetColor(-1,0x0000FF) Global $DoneCheckbox = GUICtrlCreateCheckbox("Done: ",540,20) GUICtrlSetResizing(-1,802) GUICtrlSetState(-1,$GUI_CHECKED) Global $DoneLabel = GUICtrlCreateLabel(0,593,22,30) GUICtrlSetResizing(-1,802) GUICtrlSetFont(-1,12) GUICtrlSetColor(-1,0x0000FF) Global $hListView = GUICtrlCreateListView("", 10, 60, $wWidth-20, $wHeight-110, $iListViewStyle, $iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle) GUICtrlSetResizing(-1,102) $OpenFolderButton = GUICtrlCreateButton("Open Folder",10,460,120,30) GUICtrlSetResizing(-1,834) $StartButton = GUICtrlCreateButton("Start",670,460,120,30) GUICtrlSetResizing(-1,836) $RefreshButton = GUICtrlCreateButton("Refresh", 10, 15, 120, 30) GUICtrlSetResizing(-1,802) GUISetState() For $i=1 To $ColumnHeaders[0] _GUICtrlListView_AddColumn($hListView, $ColumnHeaders[$i]) Next Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] _Refresh($hListView) _GUICtrlListView_RegisterSortCallBack($hListView) While 1 $msg = GUIGetMsg() Switch $msg Case $RefreshButton MsgBox(0,"ControlID",$msg) _Refresh($hListView) Case $OpenFolderButton MsgBox(0,"ControlID",$msg) $CheckedItems = _GetCheckedItems() If $CheckedItems[0] > 0 Then _OpenFolder($CheckedItems) Else MsgBox(16,"Error","No items selected!") EndIf Case $StartButton MsgBox(0,"ControlID",$msg) $CheckedItems = _GetCheckedItems() If $CheckedItems[0] > 0 Then _Start($CheckedItems) Else MsgBox(16,"Error","No items selected!") EndIf Case $hListView MsgBox(0,"ControlID",$msg) _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView)) Case $GUI_EVENT_CLOSE MsgBox(0,"ControlID",$msg) Exit EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($hListView) EndFunc ;==>Main Func _Refresh(ByRef $hWnd) Dim $CheckboxState[5][3] = [[4,""], [ _ "1_Not Ready", GUICtrlRead($NotReadyCheckbox), $NotReadyLabel], [ _ "2_Ready", GUICtrlRead($ReadyCheckbox), $ReadyLabel], [ _ "3_Processing", GUICtrlRead($ProcessingCheckbox), $ProcessingLabel], [ _ "4_Done", GUICtrlRead($DoneCheckbox), $DoneLabel]] _GUICtrlListView_BeginUpdate($hWnd) _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hWnd)) Dim $AllFilesToAdd[16] = [ _ "File1|2000k|0|3|0|3|0|1_Not Ready", _ "File2|2000k|0|3|0|3|0|1_Not Ready", _ "File3|2000k|0|3|0|3|0|1_Not Ready", _ "File4|2000k|0|3|0|3|0|1_Not Ready", _ "File5|1000k|1|74|3|74|100|4_Done", _ "File6|1000k|1|68|0|68|100|4_Done", _ "File7|1000k|2|55|0|55|100|4_Done", _ "File8|300k|3|55|1|54|98|3_Processing", _ "File9|2000k|3|3|0|1|33|2_Ready", _ "File10|8000k|1|68|0|68|100|4_Done", _ "File11|8000k|4|55|0|55|100|4_Done", _ "File12|300k|1|74|0|74|100|4_Done", _ "File13|8000k|1|68|0|68|100|4_Done", _ "File14|300k|1|74|0|74|100|4_Done", _ "File15|2000k|3|3|0|0|0|2_Ready", _ "File16|1000k|1|68|0|68|100|4_Done"] If IsArray($AllFilesToAdd) Then For $i In $AllFilesToAdd _AddRow($hWnd,$i) Next EndIf For $i=0 To $ColumnHeaders[0]-1 _GUICtrlListView_SetColumnWidth($hWnd, $i, $LVSCW_AUTOSIZE_USEHEADER) Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==> _Refresh Func _AddRow(ByRef $hWnd, $sItem) Local $aItem = StringSplit($sItem, "|") If StringInStr($sItem,"1_Not Ready") > 0 Then $LineColor = 0 ElseIf StringInStr($sItem,"2_Ready") > 0 Then $LineColor = 1 ElseIf StringInStr($sItem,"3_Processing") > 0 Then $LineColor = 2 ElseIf StringInStr($sItem,"4_Done") > 0 Then $LineColor = 3 Else $LineColor = 4 EndIf Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $LineColor, _GUICtrlListView_GetItemCount($hWnd)) $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hWnd, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hWnd, 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hWnd, 0xFF00FF, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hWnd, 0x0000FF, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hWnd, 0x000000, 16, 16)) _GUICtrlListView_SetImageList($hWnd, $hImage, 1) _GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER) For $x = 2 To $aItem[0] _GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1) Next EndFunc ;==> _AddRow Func _GetCheckedItems() $TotalItems = _GUICtrlListView_GetItemCount($hListView) Dim $cItems[1] = [0] For $i=0 To $TotalItems-1 If _GUICtrlListView_GetItemChecked($hListView, $i) Then _ArrayAdd($cItems,$i) $cItems[0]+=1 EndIf Next If $cItems[0] = 0 Then For $i=0 To $TotalItems-1 If _GUICtrlListView_GetItemSelected($hListView, $i) Then _ArrayAdd($cItems,$i) $cItems[0]+=1 EndIf Next EndIf ;~ _ArrayDisplay($cItems) Return $cItems EndFunc ;==> _GetCheckedItems Func _OpenFolder(ByRef $cItems) For $i=1 To $cItems[0] $TempArray = _GUICtrlListView_GetItemTextArray($hListView,$cItems[$i]) Run("explorer.exe " & $TempArray[2]) Next EndFunc ;==> _OpenFolder Func _Start(ByRef $cItems) For $i=1 To $cItems[0] Dim $FilesToRun[1] = [0] Dim $TempFiles[1] = [0] $TempArray = _GUICtrlListView_GetItemTextArray($hListView,$cItems[$i]) If $TempArray[8] = "1_Not Ready" Or $TempArray[8] = "4_Done" Then MsgBox(16,"Error","No files need to be ran!") Else $Path = "C:\" & $TempArray[1] & "\" $TempFiles = _FileListToArray($Path,"*",1) _ArrayConcatenate($FilesToRun,$TempFiles) _ArrayDelete($FilesToRun,0) EndIf If IsArray($TempFiles) Then For $x=1 To $FilesToRun[0] Run("Notepad.exe" & " " & $Path & $FilesToRun[$x]) Sleep(250) Next EndIf Next EndFunc ;==> _Start Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 14, 2012 Moderators Share Posted April 14, 2012 (edited) egridley,That took some finding! The problem is in this line:Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $LineColor, _GUICtrlListView_GetItemCount($hWnd))AutoIt uses the final $iParam parameter in ListViews and TreeViews to store the ControlID of the item when it is created by the native GUICtrlCreateListViewItem function - you are creating the Items using the UDF _GUICtrlListView_AddItem function which does not return a ControlID as the control is not included in AutoIt's internal list. By setting that parameter to a value which repeats existing ControlIDs, AutoIt is getting confused and firing the native control whenever the UDF control is clicked. Two solutions to solve this:- 1. Do not set that parameter - at present you are only repeating the index number of the Item. Do you need to use the parameter elsewhere in the script?- 2. Make sure the parameter is not a repeat of an existing control - perhaps add 1000 to it so that there is no conflict:Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $LineColor, 1000 +_GUICtrlListView_GetItemCount($hWnd))All clear? M23 Edited April 14, 2012 by Melba23 Formatting screwed up 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 Link to comment Share on other sites More sharing options...
egridley Posted April 16, 2012 Author Share Posted April 16, 2012 Melba23, Thank you so much! That was driving me crazy. I found that without that parameter, sorting by clicking on the column header wouldn't work at all. I'm not quite sure why. Anyway, your second solution of just adding a set number to it is working nicely. I would never have figured that one out on my own, so thanks again! Link to comment Share on other sites More sharing options...
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