Jump to content

ComboBox trouble


gigilihooie
 Share

Recommended Posts

So, I want to have a combobox with a list of things in it. You click one of the things and it will do something (below is an example which I cant get to work).

#include <GUIConstantsEx.au3>

    GUICreate("My GUI combo")
    $go = GUICtrlCreateButton("ok", 10, 100, 155, 17, 0)
    $ok = GUICtrlCreateCombo("1", 10, 10)
    GUICtrlSetData(-1, "2")
    
    GUISetState()
    
    While 1
        $msg = GUIGetMsg()
        select
            Case $go
                If $ok =1 Then Exit
                If $ok =2 Then Exit
        
            If $msg = $GUI_EVENT_CLOSE Then Exit
        EndSelect
    WEnd
Link to comment
Share on other sites

You have to GuiCtrlRead to get the data from the combo:

#include <GUIConstantsEx.au3>

GUICreate("My GUI combo")
$go = GUICtrlCreateButton("ok", 10, 100, 155, 17, 0)
$ok = GUICtrlCreateCombo("1", 10, 10)
GUICtrlSetData(-1, "2")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $go
            If GUICtrlRead($ok) = 1 Then MsgBox(0, "", "1")
            If GUICtrlRead($ok) = 2 Then MsgBox(0, "", "2")
            
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Also fixed the way you were trying to capture the Gui_Event_Close

Edit: This would also be a good place to use a Switch instead of Select:

#include <GUIConstantsEx.au3>

GUICreate("My GUI combo")
$go = GUICtrlCreateButton("ok", 10, 100, 155, 17, 0)
$ok = GUICtrlCreateCombo("1", 10, 10)
GUICtrlSetData(-1, "2")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg 
        Case $go
            If GUICtrlRead($ok) = 1 Then MsgBox(0, "", "1")
            If GUICtrlRead($ok) = 2 Then MsgBox(0, "", "2")
            
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by ResNullius
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...