#include Once "window9.bi"

Sub DeleteTreeViewItemAll(iGadget As Long)
    
    dim as hwnd tree = GadgetID(iGadget)	
    dim as Integer iDelNode
    dim as Integer iTempNode = Cast(Integer,SendMessage(Gadgetid(iGadget),TVM_GETNEXTITEM,TVGN_ROOT,Cast(LPARAM,0)))
    dim as integer imgList = Cast(Integer,GetHimageCombo_(iGadget))  
    dim as any ptr pStackIndexes = GetProp(tree, "stackindexes")
    
    While iTempNode
        iDelNode = iTempNode
        iTempNode = Cast(Integer,SendMessage(Gadgetid(iGadget),TVM_GETNEXTITEM,TVGN_NEXT,Cast(LPARAM,iTempNode)))
        SendMessage(tree,TVM_DELETEITEM,0,Cast(lparam,iDelNode))
    Wend
    
    if imgList then
        ImageList_RemoveAll(cast(any ptr ,imgList))
    EndIf
    
    if pStackIndexes then
        FreeStackFreeIndexes(pStackIndexes)
    EndIf
    
End Sub