Jump to content

Get Select item text in listbox


Go to solution Solved by abberration,

Recommended Posts

hey guys 

i tried to get select item text in listbox but its getting fail ...

this is the code :

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 254, 233, 516, 270)
$List1 = GUICtrlCreateList("", 16, 8, 217, 149)
$Button1 = GUICtrlCreateButton("Button1", 80, 176, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $sItems


Local $aaa
$sData = "|" & StringReplace(FileRead(@ScriptDir & "\12.txt"), @CRLF, "|")
GUICtrlSetData($List1, $sData)
While 1
$aaa = GUIGetMsg()
Select
Case $aaa=$GUI_EVENT_CLOSE
ExitLoop
Case $aaa=$Button1
_GUICtrlListBox_SetSel($sItems, 1)
   $sItems = _GUICtrlListBox_GetSelItemsText($List1)
MsgBox(4160, "Information", "Items Selected: " & $sItems)
EndSelect
WEnd

:sweating:

Link to comment
Share on other sites

  • Solution

I have played with your code until I have it working how you want. At least this is what I think you want. Look at the comments and they should help you.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <array.au3>

$Form1 = GUICreate("Form1", 254, 233, 516, 270)
$List1 = GUICtrlCreateList("", 16, 8, 217, 149, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL)) ; BitOR style taken from help file
$sItems = "1|2|3|4|5" ; To simplify, no txt list. Just this one for testing purposes.
GUICtrlSetData($List1, $sItems)
_GUICtrlListBox_SetSel($List1, 1) ; Set position 1 (which is the 2nd in list) as default
$Button1 = GUICtrlCreateButton("Button1", 80, 176, 75, 25)
GUISetState(@SW_SHOW)

Local $aaa

While 1
    $aaa = GUIGetMsg()
    Select
        Case $aaa = $GUI_EVENT_CLOSE
            ExitLoop
        Case $aaa = $Button1
            $selItems = _GUICtrlListBox_GetSelItemsText($List1) ; Read the selected item characteristics to an array
            MsgBox(4160, "Information", "Item Selected: " & $selItems[1]) ; $selItems[1] cooresponds to the the selected text value in this array
    EndSelect
WEnd
Edited by abberration
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...