Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Get selected item from a ListBox



  • Please log in to reply
9 replies to this topic
kmccmk9
  • Members
  • 46 posts
  • Last active: Aug 08 2014 07:50 PM
  • Joined: 11 Dec 2013

Hello,

 

I have done a lot of research but I haven't found much. Is this simply not possible? I see a lot for ListView. Would it be easy to switch a ListBox to a ListView if it doesn't work?



Oldman
  • Members
  • 2475 posts
  • Last active: Feb 18 2015 04:57 PM
  • Joined: 01 Dec 2013

After a "Gui, Submit command" or with a "GuiControlGet" command.


Si ton labeur est dur et que tes résultats sont minces, souviens toi du grand chêne qui avant n'était qu'un gland....comme toi ! (anonyme) ;)

L'art de lire, c'est l'art de penser avec un peu d'aide. (É. Faguet)

Windows 3.1. Collector's Edition.     (www.avaaz.org)


kmccmk9
  • Members
  • 46 posts
  • Last active: Aug 08 2014 07:50 PM
  • Joined: 11 Dec 2013

After a "Gui, Submit command" or with a "GuiControlGet" command.

Hi so something like this? So the selected item would go into serialslist? 

 

GUI, Font, s20 cSilver, Arial
GUI, Add, Text,,To-Do List:
Gui Color, , 4C4C4C
GUI, Add, ListBox, w500 h300 vserialslist, %serialslist%
GUI, Color, 333333
Gui, Show

In another function:
Gui, Submit
MsgBox %serialslist%

Unless, you are thinking it would be wise to use AltSubmit, get the index returned, then loop until that index?



Oldman
  • Members
  • 2475 posts
  • Last active: Feb 18 2015 04:57 PM
  • Joined: 01 Dec 2013

You can also have an array or a pseudo-array with the different values.


Si ton labeur est dur et que tes résultats sont minces, souviens toi du grand chêne qui avant n'était qu'un gland....comme toi ! (anonyme) ;)

L'art de lire, c'est l'art de penser avec un peu d'aide. (É. Faguet)

Windows 3.1. Collector's Edition.     (www.avaaz.org)


kmccmk9
  • Members
  • 46 posts
  • Last active: Aug 08 2014 07:50 PM
  • Joined: 11 Dec 2013

You can also have an array or a pseudo-array with the different values.

Is there a way to get the listbox to submit the index to a different variable so I don't destroy the variable that contains the list data?



faqbot
  • Members
  • 997 posts
  • Last active:
  • Joined: 10 Apr 2012

Yes that should work - there are two methods, where the variable is passed on and one where the index iis passed on try both below to see the difference (comment one of the listbox lines, then the other) [ edited after oldmans good suggestion - variable name]

serialslist=a|b|c|d|e
GUI, Font, s20 cSilver, Arial
GUI, Add, Text,,To-Do List:
Gui Color, , 4C4C4C
GUI, Add, ListBox, w500 h300 vSerialnumber, %serialslist%
;GUI, Add, ListBox, w500 h300 vSerialnumber altsubmit, %serialslist%
Gui, Add, Button, ,OK
GUI, Color, 333333
Gui, Show
return

ButtonOK:
Gui, Submit
MsgBox variable (selected) %Serialnumber%

Return


Oldman
  • Members
  • 2475 posts
  • Last active: Feb 18 2015 04:57 PM
  • Joined: 01 Dec 2013

Is there a way to get the listbox to submit the index to a different variable so I don't destroy the variable that contains the list data?

 

It would be better to give another name to the associate output variable (i.e. serialNumber) than serialslist.

GUI, Font, s20 cSilver, Arial
GUI, Add, Text,,To-Do List:
Gui Color, , 4C4C4C
GUI, Add, ListBox, w500 h300 vserialNumber, %serialslist%
GUI, Color, 333333
Gui, Show

In another function:
Gui, Submit
MsgBox %serialNumber%

Si ton labeur est dur et que tes résultats sont minces, souviens toi du grand chêne qui avant n'était qu'un gland....comme toi ! (anonyme) ;)

L'art de lire, c'est l'art de penser avec un peu d'aide. (É. Faguet)

Windows 3.1. Collector's Edition.     (www.avaaz.org)


kmccmk9
  • Members
  • 46 posts
  • Last active: Aug 08 2014 07:50 PM
  • Joined: 11 Dec 2013

Thanks for the replies! Ok so I tried the following but the MsgBox doesn't print a value for serialnumber.

 

GUI, Font, s20 cSilver, Arial
GUI, Add, Text,,To-Do List:
Gui Color, , 4C4C4C
GUI, Add, ListBox, w500 h300 vserialnumber AltSubmit, %serialslist%
GUI, Color, 333333
Gui, Show


In another function:
GUI, Submit
MsgBox variable (selected) %serialnumber%


faqbot
  • Members
  • 997 posts
  • Last active:
  • Joined: 10 Apr 2012
✓  Best Answer
AltSubmit: Uses alternate submit method. For DropDownList, ComboBox, and ListBox this causes the Gui Submit command to store the position of the selected item rather than its text - see http://ahkscript.org...i.htm#AltSubmit - I take it you do see 1-2-3-4 or 5 in the msgbox so remove altsubmit to get the selected value not the position.

kmccmk9
  • Members
  • 46 posts
  • Last active: Aug 08 2014 07:50 PM
  • Joined: 11 Dec 2013

AltSubmit: Uses alternate submit method. For DropDownList, ComboBox, and ListBox this causes the Gui Submit command to store the position of the selected item rather than its text - see http://ahkscript.org...i.htm#AltSubmit - I take it you do see 1-2-3-4 or 5 in the msgbox so remove altsubmit to get the selected value not the position.

No, I was expecting to see a 1,2,3,4,5,etc but I don't get anything. Also, removing altsubmit didn't fix it either.