david1337 Posted September 28, 2016 Share Posted September 28, 2016 Hey guys Quick question: In this GUI the listview is created from items in test.txt I would like my "Get Info" button to show the actual text of the item that is selected. So far I have been able to make it show the number of the item. What is the last missing puzzle here? expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> Global $MainGUI_ManageItemList Global $File = "test.txt" Global $FileToArray = FileReadToArray("test.txt") Call ("MainGUI_ManageItemList") Func MainGUI_ManageItemList() Local $Button1 $MainGUI_ManageItemList = GUICreate("Manage Item List", 800, 400, -1, -1) $cLV = GUICtrlCreateListView("[items]", 10, 10, 400, 775, $LVS_NOCOLUMNHEADER) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $Button1 = GUICtrlCreateButton("Button 1", 425, 10, 80, 30) $RemoveItem = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30) $GetInfo = GUICtrlCreateButton("GetInfo", 425, 120, 80, 30) GUISetState(@SW_SHOW, $MainGUI_ManageItemList) ; Intialise ListView Global $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 MsgBox(0,"","Button 1 is pressed") Case $RemoveItem _GUIListViewEx_Delete() Case $GetInfo $iIndex = _GUICtrlListView_GetSelectedIndices($cLV) msgbox (0, "Selected item", $iIndex) EndSwitch WEnd EndFunc ;==>Main Link to comment Share on other sites More sharing options...
l3ill Posted September 28, 2016 Share Posted September 28, 2016 Use: _GUICtrlListView_GetSelectedIndices in conjunction with: _GUICtrlListView_GetItemText See my Snippet Browser for an example My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
david1337 Posted September 28, 2016 Author Share Posted September 28, 2016 (edited) Bill ! My new best friend If I define the item number like this: _GUICtrlListView_GetItemText($cLV, 1) Then it shows the text of item 1 correct. And since _GUICtrlListView_GetSelectedIndices gets the item number of the selected item, I thought that I could do like this, but it doesn't work. The 2nd msgbox is just blank. Case $GetInfo $iIndex = _GUICtrlListView_GetSelectedIndices($cLV) $iIndexText = _GUICtrlListView_GetItemText($cLV, $iIndex) msgbox (0, "Selected item NUMBER", $iIndex) msgbox (0, "Selected item TEXT", $iIndexText) Edited September 28, 2016 by david1337 Link to comment Share on other sites More sharing options...
l3ill Posted September 28, 2016 Share Posted September 28, 2016 31 minutes ago, david1337 said: Bill ! My new best friend Try the Array Based Parameter: Case $GetInfo $iIndex = _GUICtrlListView_GetSelectedIndices($cLV, True) $iIndexText = _GUICtrlListView_GetItemText($cLV, $iIndex[1]) My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
david1337 Posted September 28, 2016 Author Share Posted September 28, 2016 Omg I can't believe this fix I just made up Case $GetInfo $iIndex = _GUICtrlListView_GetSelectedIndices($cLV) $iIndexNumber = $iIndex -"" $iIndexText = _GUICtrlListView_GetItemText($cLV, $iIndexNumber) msgbox (0, "Selected item NUMBER", $iIndex) msgbox (0, "Selected item TEXT", $iIndexText) Link to comment Share on other sites More sharing options...
l3ill Posted September 28, 2016 Share Posted September 28, 2016 Neat... whatever works My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
david1337 Posted September 28, 2016 Author Share Posted September 28, 2016 Oh, I didn't see your fix - that works great too, and somehow seems prettier Btw do you know if it's possible to set a case as soon as an item in the list is highlighted? Or is a button always needed? Link to comment Share on other sites More sharing options...
l3ill Posted September 28, 2016 Share Posted September 28, 2016 Not off hand... You could make a Function out of it and call it from one of the the functions in Melbas UDF, you would have to read up on how that's done though. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
l3ill Posted September 28, 2016 Share Posted September 28, 2016 39 minutes ago, david1337 said: Oh, I didn't see your fix - that works great too, and somehow seems prettier Well yours works for now but when you start adding code and intricacies it may cause problems down the road. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
l3ill Posted September 28, 2016 Share Posted September 28, 2016 For instance if you were using the Default Version of _GUICtrlListView_Create you could call your case with the following: $LVS_EX_ONECLICKACTIVATE - The control sends an $LVN_ITEMACTIVATE messages when the user clicks an item Melbas probably has something similar better ;-) My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
david1337 Posted September 28, 2016 Author Share Posted September 28, 2016 (edited) Haha I'm sure Melba has something just like that superior *poke poke Melba* Edited September 28, 2016 by david1337 Link to comment Share on other sites More sharing options...
david1337 Posted September 28, 2016 Author Share Posted September 28, 2016 Oh god scripting can be frustrating: When NO item is selected and the "Get Info" button is clicked, the script crashes with: Array variable has incorrect number of subscripts or subscript dimension range exceeded I guess that array bug is still haunting here huh? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2016 Moderators Share Posted September 28, 2016 david1337, Someone called? This seems to work nicely: Case $GetInfo $aIndex = _GUICtrlListView_GetSelectedIndices($cLV, True) If IsArray($aIndex) And $aIndex[0] <> 0 Then MsgBox(0, "Selected item", _GUICtrlListView_GetItemText( $cLV, $aIndex[1])) EndIf And as you are checking that there is at least one item selected, you do not get a crash when one is 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 Link to comment Share on other sites More sharing options...
david1337 Posted September 28, 2016 Author Share Posted September 28, 2016 Melba, Exactly! Worked perfectly. Clever way to attack the issue Thank you! - Now, can I please request for a function like this in the forum? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2016 Moderators Share Posted September 28, 2016 (edited) david1337, Nice thought - but as has just been proved, I normally turn up fairly quickly in any event! M23 Edited September 28, 2016 by Melba23 Typo 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...
david1337 Posted September 28, 2016 Author Share Posted September 28, 2016 You sure do 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