Pook Posted January 5, 2012 Posted January 5, 2012 Okay, I've been looking in the Help file at all the GUICtrlListView_GetItem /GetItemChecked / ClickItem and so on. What I'm trying to do is get the highlighted item in the listview to use in other functions. For Example: I'm making a GUI to Edit an INI file. The GUI show all the Free Spots in the INI file that you can add something to. But I can't get the function to read what item in the list is highlighted. ** Attached Screenshot Any Idea.. I know I'm just missing it in the help-file, or I just don't understand what I'm reading.
Moderators Melba23 Posted January 5, 2012 Moderators Posted January 5, 2012 Pook,Is this a native or UDF created ListView? If native, then GUICtrlRead should work.If UDF, then use _GUICtrlListView_GetSelectedIndices.Post some simple reproducer code if you still have problems. 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
Pook Posted January 5, 2012 Author Posted January 5, 2012 Tried both the examples in the Help file. Still not sure what I'm missing. expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiListBox.au3> ; Added to Master script #include <GuiImageList.au3> ; Added to Master script #include <GuiListView.au3> ; Added to Master script Global $hListView ; List ViewName _GUIBOX() Func _GUIBOX() $FormAR1 = GUICreate("TEST -", 737, 449, 192, 114) $RemoveButton3 = GUICtrlCreateButton("GO", 472, 397, 105, 33) $ButtonExit = GUICtrlCreateButton("Exit", 615, 398, 113, 33) _Add_RemoveListview() ; Build List View GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ; Exit Top buttom Exit Case $ButtonExit ; Exit Button Exit Case $RemoveButton3 ; Remove Button _AddAppINI() EndSwitch WEnd Endfunc Func _Add_RemoveListview() ; Fucntion to list INI applicaton Information Local $hImage, $hListView $hListView = GUICtrlCreateListView("", 435, 31, 300, 337) _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT) ; Load images $hImage = _GUIImageList_Create() ;1 = Green 1 = red 2 = Blue _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x0000FF, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF6600, 16, 16)) _GUICtrlListView_SetImageList($hListView, $hImage, 1) ;0 = Green 1 = red 2 = Blue ; Add columns _GUICtrlListView_AddColumn($hListView, "App #", 65) _GUICtrlListView_AddColumn($hListView, "App Name", 300) ;///////////////////////////////////////////////// ; Load INI Information in ListView (removed Loop from INI File) ;///////////////////////////////////////////////// _GUICtrlListView_AddItem($hListView, "App1", 1) _GUICtrlListView_AddSubItem($hListView, 0, "< Free Spot >", 1) _GUICtrlListView_AddItem($hListView, "App2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "< Free Spot >", 1) _GUICtrlListView_AddItem($hListView, "App3", 2) _GUICtrlListView_AddSubItem($hListView, 2, "OFFICE", 1) ;///////////////////////////////////////////////// ; Load Grouping Information in ListView ;///////////////////////////////////////////////// ; Build groups _GUICtrlListView_EnableGroupView($hListView) _GUICtrlListView_InsertGroup($hListView, -1, 1, "Software Group 1") _GUICtrlListView_InsertGroup($hListView, -1, 2, "Software Group 2") _GUICtrlListView_InsertGroup($hListView, -1, 3, "Software Group 3") _GUICtrlListView_InsertGroup($hListView, -1, 4, "Software Group 4") _GUICtrlListView_InsertGroup($hListView, -1, 5, "End Tasks") ; Add Software Group 1 For $Y = 0 To 17 _GUICtrlListView_SetItemGroupID($hListView, $Y, 1) next ; Add Software Group 2 For $Y = 18 To 36 _GUICtrlListView_SetItemGroupID($hListView, $Y, 2) next ; Add Software Group 3 For $Y = 37 To 55 _GUICtrlListView_SetItemGroupID($hListView, $Y, 3) next ; Add Software Group 4 For $Y = 56 To 74 _GUICtrlListView_SetItemGroupID($hListView, $Y, 4) next ; Add Software Group 5 (End task) For $Y = 75 To 87 _GUICtrlListView_SetItemGroupID($hListView, $Y, 5) next EndFunc ;==>_Main Func _AddAppINI() ;///////////////////////////////////////////////// ; Read all Inputs on Form ;///////////////////////////////////////////////// MsgBox(4160, "TEST", "Selected Item from List is: " & _GUICtrlListView_GetSelectedIndices($hListView)) endfunc
Moderators Melba23 Posted January 5, 2012 Moderators Posted January 5, 2012 Pook,Declaring $hlistview as Local inside function _Add_RemoveListview means that the Global variable of the same name does not get updated - hence you get no response in function AddAppINI. Also, you should match UDF ListView and ListViewitem creation functions - mixing them usually ends in tears somewhere along the line. Finally, _GUICtrlListView_GetSelectedIndices returns an array unless you tell it not to - read the Help file. This works for me:expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiListBox.au3> ; Added to Master script #include <GuiImageList.au3> ; Added to Master script #include <GuiListView.au3> ; Added to Master script Global $hListView ; List ViewName _GUIBOX() Func _GUIBOX() $FormAR1 = GUICreate("TEST -", 737, 449, 192, 114) $RemoveButton3 = GUICtrlCreateButton("GO", 472, 397, 105, 33) $ButtonExit = GUICtrlCreateButton("Exit", 615, 398, 113, 33) _Add_RemoveListview($FormAR1) ; Build List View GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ; Exit Top buttom Exit Case $ButtonExit ; Exit Button Exit Case $RemoveButton3 ; Remove Button _AddAppINI() EndSwitch WEnd Endfunc Func _Add_RemoveListview($FormAR1) ; Fucntion to list INI applicaton Information Local $hImage $hListView = _GUICtrlListView_Create($FormAR1, "", 435, 31, 300, 337) _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT) ; Load images $hImage = _GUIImageList_Create() ;1 = Green 1 = red 2 = Blue _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x0000FF, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF6600, 16, 16)) _GUICtrlListView_SetImageList($hListView, $hImage, 1) ;0 = Green 1 = red 2 = Blue ; Add columns _GUICtrlListView_AddColumn($hListView, "App #", 65) _GUICtrlListView_AddColumn($hListView, "App Name", 300) ;///////////////////////////////////////////////// ; Load INI Information in ListView (removed Loop from INI File) ;///////////////////////////////////////////////// _GUICtrlListView_AddItem($hListView, "App1", 1) _GUICtrlListView_AddSubItem($hListView, 0, "< Free Spot >", 1) _GUICtrlListView_AddItem($hListView, "App2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "< Free Spot >", 1) _GUICtrlListView_AddItem($hListView, "App3", 2) _GUICtrlListView_AddSubItem($hListView, 2, "OFFICE", 1) ;///////////////////////////////////////////////// ; Load Grouping Information in ListView ;///////////////////////////////////////////////// ; Build groups _GUICtrlListView_EnableGroupView($hListView) _GUICtrlListView_InsertGroup($hListView, -1, 1, "Software Group 1") _GUICtrlListView_InsertGroup($hListView, -1, 2, "Software Group 2") _GUICtrlListView_InsertGroup($hListView, -1, 3, "Software Group 3") _GUICtrlListView_InsertGroup($hListView, -1, 4, "Software Group 4") _GUICtrlListView_InsertGroup($hListView, -1, 5, "End Tasks") ; Add Software Group 1 For $Y = 0 To 17 _GUICtrlListView_SetItemGroupID($hListView, $Y, 1) next ; Add Software Group 2 For $Y = 18 To 36 _GUICtrlListView_SetItemGroupID($hListView, $Y, 2) next ; Add Software Group 3 For $Y = 37 To 55 _GUICtrlListView_SetItemGroupID($hListView, $Y, 3) next ; Add Software Group 4 For $Y = 56 To 74 _GUICtrlListView_SetItemGroupID($hListView, $Y, 4) next ; Add Software Group 5 (End task) For $Y = 75 To 87 _GUICtrlListView_SetItemGroupID($hListView, $Y, 5) next EndFunc ;==>_Main Func _AddAppINI() ;///////////////////////////////////////////////// ; Read all Inputs on Form ;///////////////////////////////////////////////// MsgBox(4160, "TEST", "Selected Item from List is: " & _GUICtrlListView_GetSelectedIndices($hListView, False)) endfuncAll clear? Please ask if not. 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
Pook Posted January 5, 2012 Author Posted January 5, 2012 Wow.. something that looks so simple just killed 5 hours of my time. I'm guessing the local part kept all the other things I tried from working. Also thanks for the code idea. I'll clean it up to make sure I'm using the functions from the UDF.
Moderators Melba23 Posted January 5, 2012 Moderators Posted January 5, 2012 Pook,something that looks so simple just killed 5 hours of my timeSo often the case! Glad I could help. 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