Jump to content

Combo Box selection text?

Go to solution Solved by LarsJ,

Recommended Posts


I have a combo box that I want to create the selectable options in a dynamic way. So I feel terrible for asking but I'm just not finding it in the search or in the help. It looks like you can only retrieve the number of the item selection, is there a way to grab the actual text content of the selection instead?

IE my string is made up like this:

$string =  '"a|b|c|d|e|f|g", "c"'

GUICtrlSetData($GUI_Combo_Action, $string)

Because $string would actually be created dynamically I don't know how to associate an action when all I need to know is the actual text value of the selection. In this case, how do I retrieve "c" as it's value instead of  "2"

I'm so sorry if this has been asked, which I'm sure it has- I'm just tired and not finding what I need for this project. Any help is greatly appreciated.



Link to post
Share on other sites

On GuiCtrlSetData, you can set the default value with the third criteria - ex: GuiCtrlSetData(control, data, default).

In the case you listed above, it would be something like:

$string =  "a|b|c|d|e|f|g"
$default = "c"
GuiCtrlSetData($GUI_Combo_Action, $string, $default)


Is that close to that you wanted?

Link to post
Share on other sites
  • Solution

You can get the text with GUICtrlRead:


#include <GUIConstantsEx.au3>


Func Example()
    Local $msg, $idCombo

    GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered

    $idCombo = GUICtrlCreateCombo("item1", 10, 10) ; create first item
    GUICtrlSetData($idCombo, "item2|item3", "item3") ; add other item snd set a new default
    GUICtrlSetData($idCombo, "a|b|c|d|e|f|g", "c") ; add other item snd set a new default


    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()

        If $msg = $idCombo Then _
            MsgBox( 0, "Combo text", GUICtrlRead( $idCombo ) )

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
EndFunc   ;==>Example
Link to post
Share on other sites

Thank you kindly for the replies. I had posted with the default being 'c' however if the user were to change it I would still need to be able to grab the text dynamically.

I was trying to use GUICtrlComboBox_GetCurSel($mycombo) Thank you for the pointer on GuiCtrlRead, I did no realize I could use that on a combo box- I'm not sure why I had not just tried it before. I thank you both very much for the assistance: It is greatly appreciated!!!



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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...