Function Reference


_GUICtrlListBox_SelectString

Searchs for an item that begins with the specified string

#include <GuiListBox.au3>
_GUICtrlListBox_SelectString ( $hWnd, $sText [, $iIndex = -1] )

Parameters

$hWnd Control ID/Handle to the control
$sText String that contains the string for which to search.
$iIndex [optional] Specifies the 0-based index of the item before the first item to be searched.
When the search reaches the bottom of the list box, it continues searching from the top of the list box back to the item specified by $iIndex.
If $iIndex is –1, the entire list box is searched from the beginning.

Return Value

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

Remarks

The list box is scrolled, if necessary, to bring the selected item into view.
Do not use this message with a list box that has the $LBS_MULTIPLESEL or the $LBS_EXTENDEDSEL styles.

Related

_GUICtrlListBox_FindInText, _GUICtrlListBox_FindString

Example

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

Example()

Func Example()
    Local $sText, $idListBox

    ; Create GUI
    GUICreate("List Box Select String", 400, 296)
    $idListBox = GUICtrlCreateList("", 2, 2, 396, 296)
    GUISetState(@SW_SHOW)

    ; Add strings
    _GUICtrlListBox_BeginUpdate($idListBox)
    For $iI = 1 To 10
        $sText = StringFormat("%03d : Random string ", Random(1, 100, 1))
        For $iX = 1 To Random(1, 20, 1)
            $sText &= Chr(Random(65, 90, 1))
        Next
        _GUICtrlListBox_AddString($idListBox, $sText)
    Next
    _GUICtrlListBox_AddString($idListBox, "020 : Target string")
    _GUICtrlListBox_EndUpdate($idListBox)

    ; Select string
    MsgBox($MB_SYSTEMMODAL, "Information", "Target String Index: " & _GUICtrlListBox_SelectString($idListBox, "020 : T"));

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