Function Reference


_GUICtrlTreeView_InsertItem

Insert an item

#include <GuiTreeView.au3>
_GUICtrlTreeView_InsertItem ( $hWnd, $sItem_Text [, $hItem_Parent = 0 [, $hItem_After = 0 [, $iImage = -1 [, $iSelImage = -1]]]] )

Parameters

$hWnd Control ID/Handle to the control
$sItem_Text Text of new item. See remark.
$hItem_Parent [optional] parent item ID/handle/item
$hItem_After [optional] item ID/handle/flag to insert new item after
$iImage [optional] 0-based index of the item's icon in the control's image list
$iSelImage [optional] 0-based index of the item's icon in the control's image list

Return Value

Success: the new item handle.
Failure: 0.

Remarks

If a notification callback is needed, you have to specify $sItem_Text = -1 (LPSTR_TEXTCALLBACK).

Example

#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
        GUICreate("TreeView Insert Item (v" & @AutoItVersion & ")", 400, 300)

        Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
        Local $idTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
        GUISetState(@SW_SHOW)

        ; Set ANSI format
;~     _GUICtrlTreeView_SetUnicodeFormat($idTreeView, False)

        _GUICtrlTreeView_BeginUpdate($idTreeView)
        Local $aidItem[10], $aidChildItem[30], $iYItem = 0
        For $x = 0 To 9
                $aidItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x), $idTreeView)
                For $y = 1 To 3
                        $aidChildItem[$iYItem] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $iYItem), $aidItem[$x])
                        $iYItem += 1
                Next
        Next
        _GUICtrlTreeView_EndUpdate($idTreeView)

        Local $iRand = Random(0, 9, 1)
        MsgBox($MB_SYSTEMMODAL, "Information", StringFormat("Inserted after index %d: %s", $iRand, _GUICtrlTreeView_InsertItem($idTreeView, "Inserted Item", 0, $aidItem[$iRand])))

        $iRand = Random(0, 29, 1)
        Local $hInsert = _GUICtrlTreeView_InsertItem($idTreeView, "Inserted Item", _GUICtrlTreeView_GetParentHandle($idTreeView, $aidChildItem[$iRand]), $aidChildItem[$iRand])
        MsgBox($MB_SYSTEMMODAL, "Information", StringFormat("Inserted after child index %d: %s", $iRand, $hInsert))

        $hInsert = _GUICtrlTreeView_InsertItem($idTreeView, "Inserted first child Item", _GUICtrlTreeView_GetParentHandle($idTreeView, $aidChildItem[$iRand]), $TVI_FIRST)
        MsgBox($MB_SYSTEMMODAL, "Information", StringFormat("Inserted child index %d firsts: %s", $iRand, $hInsert))
        _GUICtrlTreeView_SelectItem($idTreeView, $hInsert)

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