UDF > GUI > GuiTreeView >


_GUICtrlTreeView_InsertItem

Insére un noeud

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

Paramètres

$hWnd ID/handle du contrôle
$sItem_Text Texte du nouveau noeud. Voir remarque.
$hItem_Parent [optionnel] ID/handle/texte du noeud parent
$hItem_After [optionnel] ID/handle/flag du noeud après lequel l'insertion se fera après
$iImage [optionnel] Index, à partir de 0, de l'icône du noeud dans la liste des images du contrôle
$iSelImage [optionnel] Index, à partir de 0, de l'icône du noeud dans la liste des images du contrôle

Valeur de retour

Succès: Retourne le handle du nouveau noeud.
Échec: Retourne 0.

Remarque

Si une notification callback est nécessaire, vous devez spécifier $sItem_Text = -1 (LPSTR_TEXTCALLBACK).

Exemple

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

Example()

Func Example()
    Local $aidItem[10], $aidChildItem[30], $iYItem = 0, $iRand, $hInsert, $idTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)

    GUICreate("TreeView Insert Item", 400, 300)

    $idTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState(@SW_SHOW)

    _GUICtrlTreeView_BeginUpdate($idTreeView)
    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)

    $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)
    $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)

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