Jump to content

Selected Value of Combo Box


Kash
 Share

Recommended Posts

Hello,

How to read selected value of combo box control using autoIT?

I have below script.

GUICreate("ComboBox",225,100)

$controlID = GUICtrlCreateCombo( "---",0 ,0 ,100,10) ; create first item

GUICtrlSetData(3, " ITEM 1| ITEM2| ITEM3")

Now i would like to get selected value when it is selected by user.

Please help.

Thanks.

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>

Global $hGUI, $ComboBox

$hGUI = GUICreate('ComboBox', 200, 200)
$ComboBox = GUICtrlCreateCombo('---', 0, 0, 200, 200)
GUICtrlSetData($ComboBox, 'ITEM1|ITEM2|ITEM3')

GUISetState()
While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
            
        Case $ComboBox
            ConsoleWrite(GUICtrlRead($ComboBox) & @CRLF)
    EndSwitch
WEnd

Link to comment
Share on other sites

Thanks, it worked....

#include <GUIConstantsEx.au3>

Global $hGUI, $ComboBox

$hGUI = GUICreate('ComboBox', 200, 200)
$ComboBox = GUICtrlCreateCombo('---', 0, 0, 200, 200)
GUICtrlSetData($ComboBox, 'ITEM1|ITEM2|ITEM3')

GUISetState()
While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
            
        Case $ComboBox
            ConsoleWrite(GUICtrlRead($ComboBox) & @CRLF)
    EndSwitch
WEnd

Link to comment
Share on other sites

Use _GUICtrlComboBox_FindStringExact() to get the index of the selected item:

#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>

Global $hGUI, $ComboBox

$hGUI = GUICreate('ComboBox', 200, 200)
$ComboBox = GUICtrlCreateCombo('---', 0, 0, 200, 200)
GUICtrlSetData($ComboBox, 'ITEM1|ITEM2|ITEM3')

GUISetState()
While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit

        Case $ComboBox
            ConsoleWrite(GUICtrlRead($ComboBox) & _
        '  Index: ' & _GUICtrlComboBox_FindStringExact($ComboBox, GUICtrlRead($ComboBox)) & @CRLF)
    EndSwitch
WEnd
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...