Function Reference


_GUICtrlComboBox_SetCurSel

Select a string in the list of a ComboBox

#include <GuiComboBox.au3>
_GUICtrlComboBox_SetCurSel ( $hWnd [, $iIndex = -1] )

Parameters

$hWnd Control ID/Handle to the control
$iIndex [optional] Specifies the 0-based index of the string to select

Return Value

Success: the index of the item selected.
Failure: -1.

Remarks

If $iIndex is –1, any current selection in the list is removed and the edit control is cleared.

If $iIndex is greater than the number of items in the list or if $iIndex is –1, the return value is -1 and the selection is cleared.

Related

_GUICtrlComboBox_GetCurSel

Example

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

Example()

Func Example()
        ; Create GUI
        GUICreate("ComboBox Get/Set Cur Sel (v" & @AutoItVersion & ")", 400, 296)
        Local $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
        GUISetState(@SW_SHOW)

        ; Add files
        _GUICtrlComboBox_BeginUpdate($idCombo)
        _GUICtrlComboBox_AddDir($idCombo, @WindowsDir & "\*.exe")
        _GUICtrlComboBox_EndUpdate($idCombo)

        ; Select Item
        _GUICtrlComboBox_SetCurSel($idCombo, 2)

        ; Get Cur Sel
        MsgBox($MB_SYSTEMMODAL, "Information", "Cur Sel: " & _GUICtrlComboBox_GetCurSel($idCombo))

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>Example