Jump to content
Sign in to follow this  
monoscout999

Filling a TreeView with folders and files

Recommended Posts

monoscout999

Hello forum, i am tryning to fill a treeview with folders and files, i am using a recursive method taken from Here i am editing and editing but i can`t figure out how to make it work properly... the problem is that i don`t know how to put every item where should be.

Maybe someone else has look this before in the forum, i guess that is a common usage for a treeview, i`ve searched but i don`t find anything.

I attach a RAR with a couple of folders and TXT files for test propouses and my attempt script.

TREEVIEW.rar

Edited by monoscout999

Share this post


Link to post
Share on other sites
smartee

hi,

The solution is simpler than you may have thought. Using the same example from the wiki by Melba23, :mellow:

#include <GuiTreeView.au3>

$hGui = GUICreate("Demo1", 600, 400)
$hTreeView = _GUICtrlTreeView_Create($hGui, 10, 10, 580, 380)
GUISetState()

_GUICtrlTreeView_BeginUpdate($hTreeView)
ListFiles_ToTreeView(@ScriptDir, 0)
_GUICtrlTreeView_EndUpdate($hTreeView)

Do
Until GUIGetMsg() = -3

Func ListFiles_ToTreeView($sSourceFolder, $hItem)

    Local $sFile

    ; Force a trailing \
    If StringRight($sSourceFolder, 1) <> "\" Then $sSourceFolder &= "\"

    ; Start the search
    Local $hSearch = FileFindFirstFile($sSourceFolder & "*.*")
    ; If no files found then return
    If $hSearch = -1 Then Return ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<

    ; Now run through the contents of the folder
    While 1
        ; Get next match
        $sFile = FileFindNextFile($hSearch)
        ; If no more files then close search handle and return
        If @error Then ExitLoop ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<

        ; Check if a folder
        If @extended Then
            ; If so then call the function recursively
            ListFiles_ToTreeView($sSourceFolder & $sFile, _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile))
        Else
            ; If a file than write path and name
            _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile)
        EndIf
    WEnd

    ; Close search handle
    FileClose($hSearch)

EndFunc   ;==>ListFiles_ToTreeView

Now sigh and say of course, why didn't I try that? :)

-smartee

Share this post


Link to post
Share on other sites
monoscout999

I was so close.... :mellow: well almost... thanks smartee

Share this post


Link to post
Share on other sites
izzy12

I was searching and search for a way to do AND BAM !!!! I find this. now is it possible to display/edit the highlighted file from the treeview in a edit box and save the changes made?

Share this post


Link to post
Share on other sites
taietel

Yes, it is: just look for _GUICtrlTreeView_GetCount, _GUICtrlTreeView_GetState, FileRead, GuiCtrlCreateEdit, GuiCtrlSetData, GuiCtrlRead, FileOpen, FileWrite, FileClose in the Help file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.