Jump to content
Sign in to follow this  
Kash

Selected Value of Combo Box

Recommended Posts

Kash

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.

Share this post


Link to post
Share on other sites
Yoriz

Use GUICtrlRead

$sSelected = GUICtrlRead($controlID)


GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites
Authenticity

#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

Share this post


Link to post
Share on other sites
Kash

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

Share this post


Link to post
Share on other sites
ogeiz

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.