Sign in to follow this  
Followers 0
Kreal11

Check what item is selected in combo box

9 posts in this topic

Hi all, i created a gui with a combo box in Koda, and i need to set $example = 1 when the first element is selected, $example = 2 when the 2nd element is selected, and so. Thanks in advance for support. I already used search but there are like 1000 results...

Share this post


Link to post
Share on other sites



is a Xenobiologist Example ! Posted Image

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Thank you, it works! But there is a little problem: i want in my script that if you select a certain item from the combobox it shows a msgbox. The problem is that it shows the msgbox even if i only go over that item with the mouse. I need to show the msgbox only if the item is clicked. Then, after showing the msgbox, i need the item on the combobox to be set on the first item. How could i do this? Thanks in advance.

Share this post


Link to post
Share on other sites

I 'll be more clear if you show your script ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Ok, so here's a script example:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 197, 66, 192, 124)
$Label1 = GUICtrlCreateLabel("Choose color:", 10, 12, 93, 17)
$Combo1 = GUICtrlCreateCombo("Choose here...", 106, 10, 81, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Black|White|Red|Green|Blue|Orange")
$Button1 = GUICtrlCreateButton("Start", 50, 32, 97, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $color_chosen = GUICtrlRead($Combo1)
    Select
    Case $color_chosen = "Black"
        ;do this
    Case $color_chosen = "White"
        ;do that
    Case $color_chosen = "Red"
        MsgBox(16, "Error", "Sorry, you chose an unavailable color") ;the problem is that the msgbox is infinite
        ;here i want a code that resets the combobox
    Case $color_chosen = "Green"
        ;do something
    Case $color_chosen = "Blue"
        MsgBox(16, "Error", "Sorry, you chose an unavailable color") ;the problem is that the msgbox is infinite
        ;here i want a code that resets the combobox
    Case $color_chosen = "Orange"
        ;do something Else
    EndSelect
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Start()
    EndSwitch
WEnd

Func Start()
    ;do this
EndFunc

Share this post


Link to post
Share on other sites

Try

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 197, 66, 192, 124)
$Label1 = GUICtrlCreateLabel("Choose color:", 10, 12, 93, 17)
$Combo1 = GUICtrlCreateCombo("Choose here...", 106, 10, 81, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Black|White|Red|Green|Blue|Orange")
$Button1 = GUICtrlCreateButton("Start", 50, 32, 97, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $color_chosen = GUICtrlRead($Combo1)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $color_chosen = GUICtrlRead($Combo1)
            Switch $color_chosen
                Case "Black"
                    ;do this
                    $_Start = 1
                Case "White"
                    ;do that
                    $_Start = 1
                Case "Red", "Blue"
                    MsgBox(16, "Error", "Sorry, you chose an unavailable color") ;the problem is that the msgbox is infinite
                    $_Start =0
                    ;here i want a code that resets the combobox
                Case "Green"
                    ;do something
                    $_Start = 1
                Case "Orange"
                    ;do something Else
                    $_Start = 1
            EndSwitch
            If $_Start Then Start()
    EndSwitch
WEnd

Func Start()
    ;do this
EndFunc

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

I forget this for reset the combobox ! Posted Image

#include <GuiComboBoxEx.au3>

           ;here i want a code that resets the combobox
            _GUICtrlComboBox_SetEditText ($Combo1, "Choose here..." )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Now it works fine! You are great! Kudos :unsure:

Share this post


Link to post
Share on other sites

Now it works fine! You are great! Kudos :unsure:

Glad to help you !


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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  
Followers 0