Jump to content

Having trouble using _GUICtrlListBox_GetSelItemsText


Recommended Posts

Hello Everyone,

I am working on a GUI that has a multiple select listbox that will let users scroll through a list and pick multiple options. I am trying to read the resulting selections with _GUICtrlListBox_GetSelItemsText but it is only returning the first selected list item. I need some help figuring out how to return all of the listbox items. Ideally, i would like to return the TEXT however, i think i could work with anything. This is my first encounter working with reading arrays, which may be the source of the problem.

Here is my code set:

Global $PT1LABRequisition1List = GUICtrlCreateList("", 151, 349, 145, 58, BitOR($LBS_MULTIPLESEL,$WS_VSCROLL,$WS_BORDER))
GUICtrlSetData($PT1LABRequisition1List, "CBC:  WBC - 9.4|CBC:  WBC - 12.1|CBC:  WBC - 14.5|CBC:  WBC - 16.6|BMP: Normal|BMP: High Glucose|UA: UTI Normal|UA: UTI Abnormal|UA: UTI Critical|UC: Normal|UC: Critical")

Then later, I read that listbox with....

Global $aPT1LABRequisition1Read = _GUICtrlListBox_GetSelItemsText ($PT1LABRequisition1List)

to test, I used a MsgBox to display the results to make sure that I was getting the text from multiple selections, but everytime I only get the top selection no matter how many are selected.

This is the msgbox code I used to display the results...

MsgBox ( 0, "Results", $aPT1LABRequisition1Read )

Within the MsgBox, I also tried the variations....

$aPT1LABRequisition1Read[0]

$aPT1LABRequisition1Read[1]

$aPT1LABRequisition1Read[2]

Any help would be appreciated...

Thank you.

Link to comment
Share on other sites

What do you get if you don't use $LBS_MULTIPLESEL?

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 Gude
How 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

Hello,

If I remove the $LBS_MULTIPLESEL it does not let the end user select more than one item from the list. I found a way of pulling ALL of the items from the listbox in text format but it is messy and I feel like there must be a better way to approach this.

Here is what I have found is working:

First to define the listbox:

Global $PT1LABRequisition1List = GUICtrlCreateList("", 151, 349, 145, 58, BitOR($LBS_MULTIPLESEL,$WS_VSCROLL,$WS_BORDER))
GUICtrlSetData($PT1LABRequisition1List, "CBC:  WBC - 9.4|CBC:  WBC - 12.1|CBC:  WBC - 14.5|CBC:  WBC - 16.6|BMP: Normal|BMP: High Glucose|UA: UTI Normal|UA: UTI Abnormal|UA: UTI Critical|UC: Normal|UC: Critical")

Then to read the list box

Global $aPT1LABRequisition1Read = _GUICtrlListBox_GetSelItemsText ($PT1LABRequisition1List)
$Num1 = $aPT1LABRequisition1Read[0]
If $Num1 = 1 Then
Global $Req1Test1 = $aPT1LABRequisition1Read[1]
EndIf
If $Num1 = 2 Then
Global $Req1Test1 = $aPT1LABRequisition1Read[1]
Global $Req1Test2 = $aPT1LABRequisition1Read[2]
EndIf
If $Num1 = 3 Then
Global $Req1Test1 = $aPT1LABRequisition1Read[1]
Global $Req1Test2 = $aPT1LABRequisition1Read[2]
Global $Req1Test3 = $aPT1LABRequisition1Read[3]
EndIf
If $Num1 = 4 Then
Global $Req1Test1 = $aPT1LABRequisition1Read[1]
Global $Req1Test2 = $aPT1LABRequisition1Read[2]
Global $Req1Test3 = $aPT1LABRequisition1Read[3]
Global $Req1Test4 = $aPT1LABRequisition1Read[4]
EndIf

I go on this way with if/than statements controlling for any # of possible selected items. What I would like, is for the application to check how many items have been selected and then define either an array for the results, or a set of global variables that can be called on later outside of the function.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...