ShikiPiki Posted September 27, 2013 Share Posted September 27, 2013 I was wondering if it's possible to get the index of the item selected in a list using GUICtrlRead.What I tried:$itemSelected = GUICtrlRead($itemList,1) ;I've tried this with advanced = 0 and = 1 ConsoleWrite($itemSelected)What it returned:Product 1.What I want it to return:0Another method i tried was:$itemSelected = _GUICtrlListView_GetSelectedIndices($itemList) ConsoleWrite($itemSelected)What it returned:nothingI created the list using GUICtrlCreateList, is the reason why the second method returns nothing is because i'm not using _GUICtrlListView_Create? Thanks! -ShikiPiki Link to comment Share on other sites More sharing options...
BrewManNH Posted September 27, 2013 Share Posted September 27, 2013 ListViews and Listboxes are very different animals, the functions won't work between the two. Perhaps _GUICtrlListBox_GetSelItemsText would work for what you're looking to do. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
MilesAhead Posted September 27, 2013 Share Posted September 27, 2013 http://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlListBox_GetSelItems.htm My Freeware Page Link to comment Share on other sites More sharing options...
ShikiPiki Posted September 27, 2013 Author Share Posted September 27, 2013 (edited) ListViews and Listboxes are very different animals, the functions won't work between the two. Perhaps _GUICtrlListBox_GetSelItemsText would work for what you're looking to do.I tried implementing this and though it seems in the help file this is what i'm looking for, when i run it it seems to return nothign and gets stuck in a lull or something. $itemSelected = GUICtrlRead($itemList) ConsoleWrite($itemSelected)Returns:Product 1.When pressing Cancel or the close button GUI properly closes. $itemSelected = _GUICtrlListBox_GetSelItems($itemList);changing only this line in the entire code ConsoleWrite($itemSelected)Returns:NothingWhen pressing Cancel ot the close button GUI does not properly close and must be terminated in either program management or the tools bar.Edit: Maybe this affects the overall results but right after ConsoleWrite I delete the item selected. However, to my understanding this is done in chronological order and should not affect the overall results.Please let me know if anything is unclear or you wish for more information.Thanks for all your support Edited September 27, 2013 by ShikiPiki Thanks! -ShikiPiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2013 Moderators Share Posted September 28, 2013 ShikiPiki, $itemSelected = _GUICtrlListBox_GetSelItems($itemList);changing only this line in the entire code ConsoleWrite($itemSelected)Returns:NothingAnd if you look in the Help file, what datatype does it say is returned by _GUICtrlListBox_GetSelItems? And will that datatype be displayed in a MsgBox? You need to read about the functions suggested for yourself, not just put them blindly into your code. 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...
ShikiPiki Posted September 30, 2013 Author Share Posted September 30, 2013 (edited) ShikiPiki, And if you look in the Help file, what datatype does it say is returned by _GUICtrlListBox_GetSelItems? And will that datatype be displayed in a MsgBox? You need to read about the functions suggested for yourself, not just put them blindly into your code. M23I'm assuming this means i can't just say consolewrite for arrays and have to indicate which index in the array i want displayed?I also tried coppying their format exactly, and just replacing the variable as my own$aItems = _GUICtrlListBox_GetSelItems($itemList) For $iI = 1 To $aItems[0] If $iI > 1 Then $sItems &= ", " $sItems &= $aItems[$iI] Next MsgBox(4160, "Information", "Items Selected: " & $sItems)The message box just ends up saying "Items Selected: " Edited September 30, 2013 by ShikiPiki Thanks! -ShikiPiki Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted September 30, 2013 Moderators Solution Share Posted September 30, 2013 ShikiPiki,This works fine for me:#include <GUIConstantsEx.au3> #include <GUIListBox.au3> $hGUI = GUICreate("Test", 500, 500) $cList = GUICtrlCreateList("", 10, 10, 200, 300, BitOR($GUI_SS_DEFAULT_LIST, $LBS_EXTENDEDSEL)) GUICtrlSetData($cList, "|Item 0|Item 1|Item 2|Item 3|Item 4") $cButton = GUICtrlCreateButton("Read", 10, 400, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton $aItems = _GUICtrlListBox_GetSelItems($cList) If $aItems[0] = 0 Then $sItems ="No Sel" Else $sItems = "" For $i = 1 To $aItems[0] If $i > 1 Then $sItems &= ", " $sItems &= $aItems[$i] Next EndIf MsgBox(4160, "Information", "Items Selected: " & $sItems) EndSwitch WEndHow about 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...
ShikiPiki Posted September 30, 2013 Author Share Posted September 30, 2013 ShikiPiki,This works fine for me:#include <GUIConstantsEx.au3> #include <GUIListBox.au3> $hGUI = GUICreate("Test", 500, 500) $cList = GUICtrlCreateList("", 10, 10, 200, 300, BitOR($GUI_SS_DEFAULT_LIST, $LBS_EXTENDEDSEL)) GUICtrlSetData($cList, "|Item 0|Item 1|Item 2|Item 3|Item 4") $cButton = GUICtrlCreateButton("Read", 10, 400, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton $aItems = _GUICtrlListBox_GetSelItems($cList) If $aItems[0] = 0 Then $sItems ="No Sel" Else $sItems = "" For $i = 1 To $aItems[0] If $i > 1 Then $sItems &= ", " $sItems &= $aItems[$i] Next EndIf MsgBox(4160, "Information", "Items Selected: " & $sItems) EndSwitch WEndHow about you? M23Ah, you know what was the issue? I had to include the BitOR($GUI_SS_DEFAULT_LIST, $LBS_EXTENDEDSEL) when creating my list. How come this is the case though? I thought that these just set it so i can select multiple items, shouldnt it work still if I only wanted to select one item? Thanks! -ShikiPiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 30, 2013 Moderators Share Posted September 30, 2013 ShikiPiki,I thought that these just set it so i can select multiple items, shouldnt it work still if I only wanted to select one item?Obviously 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...
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