Function Reference

_GUICtrlListAddItem

Add an item to the List

#Include <GuiList.au3>
_GUICtrlListAddItem($h_listbox, $s_text)

 

Parameters

$h_listbox control id/control hWnd
$s_text String to add

 

Return Value

The return value is the zero-based index of the string in the list box.
If an error occurs, the return value is $LB_ERR.
If there is insufficient space to store the new string, the return value is $LB_ERRSPACE.

 

Remarks

If the list box does not have the $LBS_SORT style, the string is added to the
end of the list. Otherwise, the string is inserted into the list and the list
is sorted.

 

Related

_GUICtrlListDeleteItem, _GUICtrlListInsertItem, _GUICtrlListReplaceString, _GUICtrlListSwapString

 

Example


#include <GUIConstants.au3>
#include <GuiList.au3>

Opt ('MustDeclareVars', 1)

Dim $msg, $ret
Dim $input, $listbox, $button

GUICreate("ListBox Add Item Demo", 400, 250, -1, -1)
GUICtrlCreateLabel("Enter item to add", 25, 15)
$input = GUICtrlCreateInput("", 125, 10, 180, 25)

$listbox = GUICtrlCreateList("", 125, 40, 180, 120)
$button = GUICtrlCreateButton("Add to List", 150, 160, 120, 40)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            If (StringLen(GUICtrlRead($input)) > 0) Then
                $ret = _GUICtrlListAddItem ($listbox, GUICtrlRead($input))
                If ($ret < 0) Then
                    If ($ret == $LB_ERRSPACE) Then
                        MsgBox(16, "Error", "insufficient space to store the new strings from calling _GUICtrlListAddItem")
                    ElseIf ($ret == $LB_ERR) Then
                        MsgBox(16, "Error", "Unknown error from _GUICtrlListAddItem")
                    EndIf
                EndIf
            EndIf
    EndSelect
WEnd