UDF > GUI > GuiListBox >


_GUICtrlListBox_FindString

Recherche une chaîne

#include <GuiListBox.au3>
_GUICtrlListBox_FindString ( $hWnd, $sText [, $bExact = False] )

Paramètres

$hWnd ID/handle du contrôle
$sText Chaîne à rechercher
$bExact [optionnel] Correspondance exacte ou pas

Valeur de retour

Succès: Retourne l'index de l'élément, compté à partir de 0.
Échec: Retourne -1.

Remarques

Trouve la première chaîne de la ListBox qui commence par la chaîne spécifiée.

Si $bExact est activé, trouve la première chaîne de la ListBox qui correspond exactement à la chaîne spécifiée, sauf que la recherche n'est pas sensible à la casse.

En relation

_GUICtrlListBox_FindInText, _GUICtrlListBox_SelectString

Exemple

Exemple 1

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

Example()

Func Example()
    Local $iIndex, $idListBox

    ; Crée une GUI
    GUICreate("List Box Find String", 400, 296)
    $idListBox = GUICtrlCreateList("", 2, 2, 396, 296)

    GUISetState(@SW_SHOW)

    ; Ajoute des chaînes
    _GUICtrlListBox_BeginUpdate($idListBox)
    For $iI = 1 To 9
        _GUICtrlListBox_AddString($idListBox, StringFormat("%03d : Random string", Random(1, 100, 1)))
    Next
    _GUICtrlListBox_InsertString($idListBox, "eXaCt tExT", 3)
    _GUICtrlListBox_EndUpdate($idListBox)

    ; Trouve un élément
    $iIndex = _GUICtrlListBox_FindString($idListBox, "exa")
    _GUICtrlListBox_SetCurSel($idListBox, $iIndex)

    ; Boucle jusqu'à ce que l'utilisateur quitte.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Exemple 2

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

Example()

Func Example()
    Local $iIndex, $idListBox

    ; Crée une GUI
    GUICreate("List Box Find String Exact", 400, 296)
    $idListBox = GUICtrlCreateList("", 2, 2, 396, 296)

    GUISetState(@SW_SHOW)

    ; Ajoute des chaînes
    _GUICtrlListBox_BeginUpdate($idListBox)
    For $iI = 1 To 9
        _GUICtrlListBox_AddString($idListBox, StringFormat("%03d : Random string", Random(1, 100, 1)))
    Next
    _GUICtrlListBox_InsertString($idListBox, "eXa", 2)
    _GUICtrlListBox_InsertString($idListBox, "eXaCt tExT", 3)
    _GUICtrlListBox_EndUpdate($idListBox)

    ; Trouve un élément
    $iIndex = _GUICtrlListBox_FindString($idListBox, "exact text", True)
    _GUICtrlListBox_SetCurSel($idListBox, $iIndex)

    ; Boucle jusqu'à ce que l'utilisateur quitte.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example