Martino Posted November 8, 2017 Author Share Posted November 8, 2017 I read about _GUIListViewEx_SetEditStatus with $iMode = 9 but I find it hard to understand. Somewhere i found this code. expandcollapse popup#include <File.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> $Form = GUICreate('', 600, 600) $ListView = GUICtrlCreateListView(' ', 10, 10, 280, 580, BitOR($LVS_NOCOLUMNHEADER, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING)) $hListView = GUICtrlGetHandle($ListView) _GUICtrlListView_SetColumnWidth($ListView, 0, 258 + 100) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() $FileList = _FileListToArray('C:\WINDOWS\system32', '*.ini', 1) For $i = 1 To $FileList[0] GUICtrlCreateListViewItem($FileList[$i], $ListView) Next While 1 $Msg = GUIGetMsg() Switch $Msg Case 0 ContinueLoop Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Local $Index = DllStructGetData($tNMHDR, 'Index') Local $Code = DllStructGetData($tNMHDR, 'Code') Switch $IDFrom Case $ListView Switch $Code Case $LVN_ITEMCHANGED $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) ; if state has changed If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _ DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then ; take care of only newly selected items (not deselected ones) If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED Then $Item = _GUICtrlListView_GetItem($ListView, $Index) ConsoleWrite($Item[3] & @CR) EndIf EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY and i can understand it also a little bit more. I integrated it in my code expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> Global $GuiSamenvatting = GUICreate("Gui", 1500, 600) Global $btn_Verplaats = GUICtrlCreateButton(" save", 1250, 10, 150) GUICtrlSetState($btn_Verplaats, $GUI_ENABLE) $idListview = GUICtrlCreateListView("# | FILES | PROJECTCODE | DOCNR | DOCCODE | DOCSOORT | DOELLOCATIE ", 10, 10, 1200, 450) ;,$LVS_SORTDESCENDING) For $n = 1 To 10 ; $aantgevondenpdfen GUICtrlCreateListViewItem($n & "|" & $n & "|" & $n & "|" & $n & "|" & $n & "|" & $n & "|" & $n, $idListview) Next _GUICtrlListView_SetColumnWidth($idListview, 1, 250) _GUICtrlListView_SetColumnWidth($idListview, 2, 100) _GUICtrlListView_SetColumnWidth($idListview, 3, 70) _GUICtrlListView_SetColumnWidth($idListview, 4, 100) _GUICtrlListView_SetColumnWidth($idListview, 5, 150) _GUICtrlListView_SetColumnWidth($idListview, 6, 450) ;If $AndereExtGevonden = 1 Then ;GUICtrlCreateLabel("Andere bestandsextensies: " & $andereextensies , 800, 50, 300, 25) ;EndIf GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState(@SW_SHOW) Global $aLV_Content = _GUIListViewEx_ReadToArray($idListview) Global $iLV_Index = _GUIListViewEx_Init($idListview, $aLV_Content, 0, 0, True, 32) _GUIListViewEx_SetEditStatus($iLV_Index, "2") ; Project column editable maken _GUIListViewEx_SetEditStatus($iLV_Index, "3") ; doc NR column editable maken _GUIListViewEx_SetEditStatus($iLV_Index, "4") ; Doc type column editable maken _GUIListViewEx_MsgRegister() ; Loop until the user exits. Do Local $ArrayMetItemsListView = _GUIListViewEx_EventMonitor() ; Allow the UDF to monitor events $Msg = GUIGetMsg() Switch $Msg Case 0 ContinueLoop Case $GUI_EVENT_CLOSE ExitLoop EndSwitch If Not @error Then ; There was no error detected Switch @extended Case 1 ; Standard edit mode Local $ErIsIetsFout = 0 If $ArrayMetItemsListView <> "" Then ; If edit not aborted If $ArrayMetItemsListView[1][1] = 2 Then Local $IngevoerdeCode = $ArrayMetItemsListView[1][3] Local $AangepasteLijn = $ArrayMetItemsListView[1][0] + 1 ;$arr_gevondenprojectcode[$AangepasteLijn]= $IngevoerdeCode GUISetState(@SW_HIDE, $GuiSamenvatting) GUIDelete($GuiSamenvatting) ;MaakGuiSamenvatting () EndIf EndIf EndSwitch EndIf Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Local $Index = DllStructGetData($tNMHDR, 'Index') Local $Code = DllStructGetData($tNMHDR, 'Code') Switch $IDFrom Case $idListview Switch $Code Case $LVN_ITEMCHANGED $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) ; if state has changed If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _ DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then ; take care of only newly selected items (not deselected ones) If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED Then $Item = _GUICtrlListView_GetItem($idListview, $Index) ConsoleWrite($Item[3] & @CR) EndIf EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY But then in my console i receive the text of the item in the first column but the others column are not editable anymore. Am i placing the GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') wrong or is it not possible to combine it with _GUIListViewEx_MsgRegister() ? Strange that it's so hard to catch a click or a double click on a listitem. Link to comment Share on other sites More sharing options...
Martino Posted November 8, 2017 Author Share Posted November 8, 2017 I simplyfied my code So now i receive a message in my console but i'm not able to edit the 3th column anymore. expandcollapse popup#include <File.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include "GUIListViewEx.au3" #include <Misc.au3> Global $FileArray[11] Global $CodeArray[11] Global $ClickedLine=0 Global $GuiSamenvatting = GUICreate("Gui", 350, 450) $idListview = GUICtrlCreateListView("# | FILES | PROJECTCODE ", 10, 10, 300, 400) ;,$LVS_SORTDESCENDING) For $n = 1 To 10 ; $FileArray[$n] = "Item " & $n $CodeArray[$n] = $n GUICtrlCreateListViewItem($n & "|" & $FileArray [$n] & "|" & $CodeArray [$n] , $idListview) Next GUISetState(@SW_SHOW) Global $aLV_Content = _GUIListViewEx_ReadToArray($idListview) Global $iLV_Index = _GUIListViewEx_Init($idListview, $aLV_Content, 0, 0, True, 32) _GUIListViewEx_SetEditStatus($iLV_Index, "2") ; Project column editable maken _GUIListViewEx_MsgRegister() GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') ; Loop until the user exits. Do Local $ArrayMetItemsListView = _GUIListViewEx_EventMonitor() ; Allow the UDF to monitor events If Not @error Then ; There was no error detected Switch @extended Case 1 ; Standard edit mode If $ArrayMetItemsListView <> "" Then ; If edit not aborted If $ArrayMetItemsListView[1][1] = 2 Then Local $IngevoerdeCode = $ArrayMetItemsListView[1][3] Local $AangepasteLijn = $ArrayMetItemsListView[1][0] + 1 ;$arr_gevondenprojectcode[$AangepasteLijn]= $IngevoerdeCode GUISetState(@SW_HIDE, $GuiSamenvatting) GUIDelete($GuiSamenvatting) ;MaakGuiSamenvatting () EndIf Else if $ClickedLine <> 0 Then MsgBox($MB_OK,"Linenumber Message", "Linenumber: " & $ClickedLine ) $clickedLine = 0 EndIf EndIf EndSwitch EndIf Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Local $Index = DllStructGetData($tNMHDR, 'Index') Local $Code = DllStructGetData($tNMHDR, 'Code') Switch $IDFrom Case $idListview Switch $Code Case $LVN_ITEMCHANGED $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) ; if state has changed If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _ DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then ; take care of only newly selected items (not deselected ones) If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED Then $Item = _GUICtrlListView_GetItem($idListview, $Index) $ClickedLine = $Index + 1 ConsoleWrite("You clicked line number: " & $ClickedLine & @CR) EndIf EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 8, 2017 Moderators Share Posted November 8, 2017 Martino, Quote Strange that it's so hard to catch a click or a double click on a listitem. Blame Windows, not AutoIt, - and that is one of the reasons why I wrote my UDF. Quote I read about _GUIListViewEx_SetEditStatus with $iMode = 9 but I find it hard to understand. It is actually very simple - as this example shows: expandcollapse popup#include <GUIConstantsEx.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include "GUIListViewEx.au3" ; Place the required folder path here $sPath = @ScriptDir & "\" ; List all files in the folder $aList = _FileListToArray($sPath, "*.*",$FLTA_FILES) $hGUI = GUICreate("Test", 500, 500) $cLV = GUICtrlCreateListView("Files", 10, 30, 300, 300, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS)) _GUICtrlListView_SetExtendedListViewStyle($cLV, $LVS_EX_FULLROWSELECT) _GUICtrlListView_SetColumnWidth($cLV, 0, 270) ; Fill the ListView with the filenames For $i = 1 To $aList[0] GUICtrlCreateListViewItem($aList[$i], $cLV) Next ; Initialise the ListView within the UDF $aLVArray =_GUIListViewEx_ReadToArray($cLV) $iLVIndex = _GUIListViewEx_Init($cLV, $aLVArray) ; Set the action on double-click to run a user function _GUIListViewEx_SetEditStatus($iLVIndex, 0, 9, _ShowPDF) _GUIListViewEx_MsgRegister() GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch _GUIListViewEx_EventMonitor() WEnd ; You need these 4 parameters Func _ShowPDF($hHandle, $iIndex, $iRow, $iCol) ; get the ListView content $aLVContent = _GUIListViewEx_ReturnArray($iIndex) ; Get the selected file path by reading the returned array $sSelFile = $sPath & $aLVContent[$iRow][0] ; And here it is - you can now do what you wish with it MsgBox($MB_SYSTEMMODAL, "Selected file", $sSelFile) EndFunc As you can see, all you need to do is use _SetEditStatus to define the function to call and the UDF does it all for you. 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 Link to comment Share on other sites More sharing options...
Martino Posted November 9, 2017 Author Share Posted November 9, 2017 Quote It is actually very simple - as this example shows: M23: you made it simple indeed. Perfect example. I was going in the right direction but i was lost in the end. You showed me the light. i had an error in the custom function So code below _GUIListViewEx_SetEditStatus($iLV_Index, 1, 9, _ShowPDF) in combination with Func _ShowPDF($hHandle, $iIndex, $iRow, $iCol) ; get the ListView content $aLVContent = _GUIListViewEx_ReturnArray($iIndex) ; Get the selected file path by reading the returned array $sSelFile = $sPath & $aLVContent[$iRow][1] ; And here it is - you can now do what you wish with it ShellExecute ($sSelFile) ; because i wish to open the pdf WinActivate ("Adobe") EndFunc did it. Thank you again M23. Link to comment Share on other sites More sharing options...
Martino Posted November 9, 2017 Author Share Posted November 9, 2017 Now i can edit a listview and do something when i click a listview item. Toppic can be closed for me. Thank you all for your help. Specially the UDF of Melba23 did the trick for me. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 9, 2017 Moderators Share Posted November 9, 2017 Martino, My pleasure as always. 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 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