232showtime Posted June 30, 2016 Share Posted June 30, 2016 (edited) @Melba23, Hi good day, is there any other way to read a selected row of GUICtrlCreateListView? I tried so many things and this is the best I could do. please note I copied some script from the old post here in forums and made some modification but im still studying how DllStructCreate, DllStructGetData, $tagNMHDR works. I want to read the exact strings in a selected row for each column and send it to _column_gui, but my script is reading all the content of a row. please help me. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> #include <GUIListView.au3> Global $idListview1, $sString, $hButton0, $iLV_Index, $cLVItem, $Gui_Column, $hGUI1, $sRead1, $sRead2, $sRead3, $sReadList Global $aNew_entry_search gui1() Func gui1() $hGUI1 = GUICreate("Gui 1", 400, 400, 200, 200) $hButton0 = GUICtrlCreateButton("Load", 100, 10, 80, 30) $hButton1 = GUICtrlCreateButton("Clear 1", 10, 10, 80, 30) $hButton2 = GUICtrlCreateButton("Add", 10, 60, 80, 30) $idListview1 = GUICtrlCreateListView("", 10, 100, 180, 80, BitOR(0x0200, 0x008), BitOR(0x00000020, 0x00000001)) _GUICtrlListView_AddColumn($idListview1, "1", 150, 2) _GUICtrlListView_AddColumn($idListview1, "2", 500, 2) _GUICtrlListView_AddColumn($idListview1, "3", 50, 2) _GUICtrlListView_Scroll($idListview1, 10, 100) ; Initiate ListView within UDF $iLV_Index = _GUIListViewEx_Init($idListview1, "") $cLVItem = GUICtrlCreateDummy() ; dummy control for listview LVN_ITEMACTIVATE dblclick on item $notify = GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton1 MsgBox("", "MsgBox 1", "Clear???") _GUICtrlListView_DeleteAllItems($idListview1) Case $hButton2 ; Disable the first GUI GUISetState(@SW_DISABLE, $hGUI1) gui2() ; Re-enable the first GUI GUISetState(@SW_ENABLE, $hGUI1) Case $hButton0 _GUIListViewEx_LoadListView($iLV_Index, "Save.lvs") ; Reset column alignment _GUICtrlListView_JustifyColumn($idListview1, 0, 2) _GUICtrlListView_JustifyColumn($idListview1, 1, 2) _GUICtrlListView_JustifyColumn($idListview1, 2, 2) _WinAPI_RedrawWindow(GUICtrlGetHandle($idListview1)) Case $cLVItem ;listview dummy control ;retrieve selected listview index from dummy with GUICtrlRead() _column_gui(GUICtrlRead($cLVItem)) EndSwitch WEnd EndFunc ;==>gui1 Func gui2() $hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350) GUICtrlCreateLabel("COL1", 15, 55, 50, 50) $sString1 = GUICtrlCreateEdit("", 50, 50, 120, 25, $ES_WANTRETURN) GUICtrlCreateLabel("COL2", 15, 110, 50, 50) $sString2 = GUICtrlCreateEdit("", 50, 100, 120, 25, $ES_WANTRETURN) GUICtrlCreateLabel("COL3", 15, 165, 50, 50) $sString3 = GUICtrlCreateEdit("", 50, 160, 120, 25, $ES_WANTRETURN) $hButton3 = GUICtrlCreateButton("Save", 10, 10, 80, 30) GUISetState() While 1 ; We can only get messages from the second GUI Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton3 $sRead1 = GUICtrlRead($sString1) $sRead2 = GUICtrlRead($sString2) $sRead3 = GUICtrlRead($sString3) _GUIListViewEx_Insert($sRead1 & "|" & $sRead2 & "|" & $sRead3) ; Add item to ListView uaing UDF ;~ _GUIListViewEx_Insert($sRead2 & "||") ; Add item to ListView uaing UDF _GUIListViewEx_SaveListView($iLV_Index, "Save.lvs") GUICtrlSetState($hButton0, $GUI_ENABLE) ExitLoop EndSwitch WEnd GUIDelete($hGUI2) EndFunc ;==>gui2 ;-------------DOUBLE CLICK Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $idListview1 If Not IsHWnd($idListview1) Then $hWndListView = GUICtrlGetHandle($idListview1) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) ;DllStructCreate(AutoItCommand, Pointer) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_ITEMACTIVATE ;dblclick on item (NM_DBLCLK includes blank space in listview) ;Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) Local $iIndex = DllStructGetData($tInfo, "Index") ;~ Local $aInfo[5] = [$hWndFrom, $iIDFrom, $iCode, DllStructGetData($tInfo, "Index"), _ ;~ DllStructGetData($tInfo, "SubItem")] If $iIndex <> -1 Then ;check index: -1 indicates click was not on an item GUICtrlSendToDummy($cLVItem, $iIndex) MsgBox($MB_SYSTEMMODAL, "listview item", GUICtrlRead(GUICtrlRead($idListview1)), 2) ;~ ToolTip("You Double Clicked on" & @CRLF & "3---Column: " & $aInfo[3] & @CRLF & "4---Row: " & $aInfo[4]) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY ;------------------------_column_gui-------------- Func _column_gui($cLVItem) If IsHWnd($Gui_Column) Then GUIDelete($Gui_Column) GUISetState(@SW_SHOW, $Gui_Column) $Gui_Column = GUICreate("Edit Window", 500, 300, -1, -1, -1, -1, $hGUI1) $sReadList = GUICtrlRead(GUICtrlRead($idListview1)) $Column1_display = GUICtrlCreateInput($sReadList, 100, 20, 50, -1, 0X0800) GUICtrlCreateLabel("Column 1:", 20, 24) $Column2_display = GUICtrlCreateInput($sReadList, 100, 45, 50, -1, 0X0800) GUICtrlCreateLabel("Column 2:", 20, 49) $Column3_display = GUICtrlCreateEdit($sReadList, 100, 70, 50, -1, 0X0800) GUICtrlCreateLabel("Column 3", 20, 75) $edit_button = GUICtrlCreateButton("Edit", 500, 95) GUISetState(@SW_SHOW, $Gui_Column) MsgBox(0, "", "Success") GUISetState() While 1 ; We can only get messages from the second GUI Switch GUIGetMsg() Case $GUI_EVENT_CLOSE If IsHWnd($Gui_Column) Then GUIDelete($Gui_Column) ExitLoop Case $edit_button _GUIListViewEx_SetEditStatus($Column1_display, 1) EndSwitch WEnd EndFunc ;==>_column_gui Edited June 30, 2016 by 232showtime ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 30, 2016 Moderators Share Posted June 30, 2016 232showtime, This question has nothing to do with my GUIListViewEx UDF, so I have split it from the main UDF thread. Use the existing GUIListView UDF commands to read your ListView - like this: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; #include <GUIListView.au3> ; Already included with GUIListViewEx Global $idListview1, $sString, $hButton0, $iLV_Index, $cLVItem, $Gui_Column, $hGUI1, $sRead1, $sRead2, $sRead3, $sReadList Global $aNew_entry_search gui1() Func gui1() $hGUI1 = GUICreate("Gui 1", 800, 400, 200, 200) $hButton0 = GUICtrlCreateButton("Load", 100, 10, 80, 30) $hButton1 = GUICtrlCreateButton("Clear 1", 10, 10, 80, 30) $hButton2 = GUICtrlCreateButton("Add", 10, 60, 80, 30) $idListview1 = GUICtrlCreateListView("", 10, 100, 700, 200, BitOR(0x0200, 0x008), BitOR(0x00000020, 0x00000001)) _GUICtrlListView_AddColumn($idListview1, "1", 200, 2) _GUICtrlListView_AddColumn($idListview1, "2", 200, 2) _GUICtrlListView_AddColumn($idListview1, "3", 200, 2) _GUICtrlListView_Scroll($idListview1, 10, 100) ; Initiate ListView within UDF $iLV_Index = _GUIListViewEx_Init($idListview1, "") $cLVItem = GUICtrlCreateDummy() ; dummy control for listview LVN_ITEMACTIVATE dblclick on item $notify = GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton1 MsgBox("", "MsgBox 1", "Clear???") _GUICtrlListView_DeleteAllItems($idListview1) Case $hButton2 ; Disable the first GUI GUISetState(@SW_DISABLE, $hGUI1) gui2() ; Re-enable the first GUI GUISetState(@SW_ENABLE, $hGUI1) Case $hButton0 _GUIListViewEx_LoadListView($iLV_Index, "Save.lvs") ; Reset column alignment _GUICtrlListView_JustifyColumn($idListview1, 0, 2) _GUICtrlListView_JustifyColumn($idListview1, 1, 2) _GUICtrlListView_JustifyColumn($idListview1, 2, 2) _WinAPI_RedrawWindow(GUICtrlGetHandle($idListview1)) Case $cLVItem ;listview dummy control ;retrieve selected listview index from dummy with GUICtrlRead() _column_gui(GUICtrlRead($cLVItem)) EndSwitch WEnd EndFunc ;==>gui1 Func gui2() $hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350) GUICtrlCreateLabel("COL1", 15, 55, 50, 50) $sString1 = GUICtrlCreateEdit("", 50, 50, 120, 25, $ES_WANTRETURN) GUICtrlCreateLabel("COL2", 15, 110, 50, 50) $sString2 = GUICtrlCreateEdit("", 50, 100, 120, 25, $ES_WANTRETURN) GUICtrlCreateLabel("COL3", 15, 165, 50, 50) $sString3 = GUICtrlCreateEdit("", 50, 160, 120, 25, $ES_WANTRETURN) $hButton3 = GUICtrlCreateButton("Save", 10, 10, 80, 30) GUISetState() While 1 ; We can only get messages from the second GUI Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton3 $sRead1 = GUICtrlRead($sString1) $sRead2 = GUICtrlRead($sString2) $sRead3 = GUICtrlRead($sString3) _GUIListViewEx_Insert($sRead1 & "|" & $sRead2 & "|" & $sRead3) ; Add item to ListView uaing UDF ;~ _GUIListViewEx_Insert($sRead2 & "||") ; Add item to ListView uaing UDF _GUIListViewEx_SaveListView($iLV_Index, "Save.lvs") GUICtrlSetState($hButton0, $GUI_ENABLE) ExitLoop EndSwitch WEnd GUIDelete($hGUI2) EndFunc ;==>gui2 ;-------------DOUBLE CLICK Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $idListview1 If Not IsHWnd($idListview1) Then $hWndListView = GUICtrlGetHandle($idListview1) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) ;DllStructCreate(AutoItCommand, Pointer) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_ITEMACTIVATE ;dblclick on item (NM_DBLCLK includes blank space in listview) ;Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) Local $iIndex = DllStructGetData($tInfo, "Index") ;~ Local $aInfo[5] = [$hWndFrom, $iIDFrom, $iCode, DllStructGetData($tInfo, "Index"), _ ;~ DllStructGetData($tInfo, "SubItem")] If $iIndex <> -1 Then ;check index: -1 indicates click was not on an item GUICtrlSendToDummy($cLVItem, $iIndex) ;MsgBox($MB_SYSTEMMODAL, "listview item", GUICtrlRead(GUICtrlRead($idListview1)), 2) ;~ ToolTip("You Double Clicked on" & @CRLF & "3---Column: " & $aInfo[3] & @CRLF & "4---Row: " & $aInfo[4]) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY ;------------------------_column_gui-------------- Func _column_gui($cLVItem) If IsHWnd($Gui_Column) Then GUIDelete($Gui_Column) GUISetState(@SW_SHOW, $Gui_Column) $Gui_Column = GUICreate("Edit Window", 500, 300, -1, -1, -1, -1, $hGUI1) $aReadList = _GUICtrlListView_GetItemTextArray($idListview1, $cLVItem) ; Use this command to read the ListView line <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $Column1_display = GUICtrlCreateInput($aReadList[1], 100, 20, 50, -1, 0X0800) GUICtrlCreateLabel("Column 1:", 20, 24) $Column2_display = GUICtrlCreateInput($aReadList[2], 100, 45, 50, -1, 0X0800) GUICtrlCreateLabel("Column 2:", 20, 49) $Column3_display = GUICtrlCreateEdit($aReadList[3], 100, 70, 50, -1, 0X0800) GUICtrlCreateLabel("Column 3", 20, 75) $edit_button = GUICtrlCreateButton("Edit", 100, 95) GUISetState(@SW_SHOW, $Gui_Column) MsgBox(0, "", "Success") GUISetState() While 1 ; We can only get messages from the second GUI Switch GUIGetMsg() Case $GUI_EVENT_CLOSE If IsHWnd($Gui_Column) Then GUIDelete($Gui_Column) ExitLoop Case $edit_button ;_GUIListViewEx_SetEditStatus($Column1_display, 1) ; Why are you trying to use the UDF to edit an input control? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndSwitch WEnd EndFunc ;==>_column_gui I have increased the size of your GUI and controls - I was fed up of scrabbling around trying to see what was happening. And I have added a few comments. M23 232showtime 1 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...
232showtime Posted June 30, 2016 Author Share Posted June 30, 2016 @Melba23, Hi, sorry melba for being noob, but im doing my best to solve the problem on my own but its been a week searching and experimenting, I already tried _GUICtrlListView_GetItemTextArray but didnt work out, yours is different, and many thanks, I need to do more researching. also im confused with GUICtrlCreateDummy() please can you give me an easy example for GUICtrlCreateDummy(), I ran the example of GUICtrlCreateDummy() in autoit help file, seems like nothing is happening, please... Case $edit_button _GUIListViewEx_SetEditStatus($Column1_display, 1) ; Why are you trying to use the UDF to edit an input control? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;^^I wanted to edit the strings in case there is some typo error i see in edit window. ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 30, 2016 Moderators Share Posted June 30, 2016 232showtime, No problem - I am always happy to help those who make an effort. As to an example of dummy controls, does the script you posted not explain how they work? If not, then here is an explanation of what is happening: You create a dummy control in your GUI - this cannot be seen or actioned, other than by the GUICtrlSendToDummy function (or by an Accelerator key), but does have a ControlID which you can detect via GUIGetMsg, When you detect a doubleclick on a ListView item in the Windows message handler, you fire the dummy control and also set a value within it (in this case, the index of the item itself) The dummy control now fires and is detected by GUIGetMsg. The code then runs the _column_gui function and retrieves the stored index to pass as a parameter. The function runs and uses that parameter to retrieve the text of the item. Any clearer? And if you want to edit the retrieved text, I suggest you create the edits in which you display the 3 parts without the $ES_READONLY style. I suggest using the style constants rather then "magic numbers" - then you would have realised that 0x0800 forced the edit to be readonly. M23 232showtime 1 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...
232showtime Posted July 2, 2016 Author Share Posted July 2, 2016 Got it thanks... ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. 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