Search for a string
#include <GuiListBox.au3>
_GUICtrlListBox_FindString ( $hWnd, $sText [, $bExact = False] )
$hWnd | Control ID/Handle to the control |
$sText | String to search for |
$bExact | [optional] Exact match or not |
Success: | the 0-based index of the item. |
Failure: | -1. |
Find the first string in a list box that begins with the specified string.
If exact is specified find the first list box string that exactly matches the specified string, except that the search is not case sensitive.
_GUICtrlListBox_FindInText, _GUICtrlListBox_SelectString
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
Example()
Func Example()
Local $iIndex, $idListBox
; Create GUI
GUICreate("List Box Find String", 400, 296)
$idListBox = GUICtrlCreateList("", 2, 2, 396, 296)
GUISetState(@SW_SHOW)
; Add strings
_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)
; Find an item
$iIndex = _GUICtrlListBox_FindString($idListBox, "exa")
_GUICtrlListBox_SetCurSel($idListBox, $iIndex)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
Example()
Func Example()
Local $iIndex, $idListBox
; Create GUI
GUICreate("List Box Find String Exact", 400, 296)
$idListBox = GUICtrlCreateList("", 2, 2, 396, 296)
GUISetState(@SW_SHOW)
; Add strings
_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)
; Find an item
$iIndex = _GUICtrlListBox_FindString($idListBox, "exact text", True)
_GUICtrlListBox_SetCurSel($idListBox, $iIndex)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example