Jump to content

[SOLVED] dynamic directory treeview


caleb41610
 Share

Recommended Posts

#include <file.au3>
#include <array.au3>
#include <guiconstantsex.au3>

Dim $dynamic[1000]

Global $parent
Global $maindrive = @HomeDrive & "\"
Global $gui = GUICreate( "", 300, 400 )
GUISetState( @SW_SHOW )

Global $tree = GUICtrlCreateTreeView( 5, 5, 290, 390 )
Global $top = GUICtrlCreateTreeViewItem( $maindrive, $tree )

Func dynamiclist( $parent )
Dim $filelist = _FileListToArray( $parent )
For $i = 1 to $filelist[0]
$dynamic[$i] = GUICtrlCreateTreeViewItem( $filelist[$i], $parent )
Next
Return $dynamic
EndFunc

While 1
$msg = GUIGetMsg( )
If $msg = $GUI_EVENT_CLOSE Then Exit
If $msg = $top Then dynamiclist( $maindrive )

For $i = 1 to $dynamic[$i]
If $msg = $dynamic[$i] Then
dynamiclist( $filelist[$i] )
EndIf
Next
WEnd

Opened up a new file and wrote this up really quick. Trying to make a file browser that updates dynamically, not sure what's going wrong though. If I do the same thing without a function it seems to work. I think I'm writing the function itself wrong with the $parent part. Tried to write it to be use-able over and over like a UDF I suppose, but I'm new to that.

Any comments/suggestions, maybe I should take a different approach? I found scarce examples when searching.

Edited by caleb41610
Link to comment
Share on other sites

  • Moderators

caleb41610,

An interesting idea. My ChooseFileFolder uses a treeview to display a tree but collects all the data at the beginning - I had not considered a dynamic tree construction. Let me play with this a while. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

caleb41610,

How about this: :)

#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <File.au3>

Global $sRoot = @ScriptDir

$hGUI = GUICreate("Test", 500, 500)

$cTV = GUICtrlCreateTreeView(10, 10, 480, 350)
$hTV = GUICtrlGetHandle($cTV)

$cRoot = GUICtrlCreateTreeViewItem($sRoot, $cTV)

_Fill_Branch($cRoot, $sRoot)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            $cItem = GUICtrlRead($cTV)
            $hItem = GUICtrlGetHandle($cItem)
            $sSelectedPath = StringReplace(_GUICtrlTreeView_GetTree($hTV, $hItem), "|", "")
            If _GUICtrlTreeView_GetChildCount($hTV, $hItem) = -1 Then
                _Fill_Branch($cItem, $sSelectedPath)
            EndIf
    EndSwitch

WEnd

Func _Fill_Branch($cParent, $sPath)
    Local $aContent = _FileListToArray($sPath, "*.*", 1), $cItem
    If IsArray($aContent) Then
        For $i = 1 To $aContent[0]
            $cItem = GUICtrlCreateTreeViewItem($aContent[$i], $cParent)
            GUICtrlSetColor($cItem, 0x0000FF)
        Next
    EndIf
    $aContent = _FileListToArray($sPath, "*", 2)
    If IsArray($aContent) Then
        For $i = 1 To $aContent[0]
            $cItem = GUICtrlCreateTreeViewItem($aContent[$i] & "", $cParent)
            GUICtrlSetColor($cItem, 0xFF0000)
        Next
    EndIf
EndFunc

Any use? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

caleb41610,

How about this: :)

#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <File.au3>

Global $sRoot = @ScriptDir

$hGUI = GUICreate("Test", 500, 500)

$cTV = GUICtrlCreateTreeView(10, 10, 480, 350)
$hTV = GUICtrlGetHandle($cTV)

$cRoot = GUICtrlCreateTreeViewItem($sRoot, $cTV)

_Fill_Branch($cRoot, $sRoot)

GUISetState()

While 1

Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case Else
$cItem = GUICtrlRead($cTV)
$hItem = GUICtrlGetHandle($cItem)
$sSelectedPath = StringReplace(_GUICtrlTreeView_GetTree($hTV, $hItem), "|", "")
If _GUICtrlTreeView_GetChildCount($hTV, $hItem) = -1 Then
_Fill_Branch($cItem, $sSelectedPath)
EndIf
EndSwitch

WEnd

Func _Fill_Branch($cParent, $sPath)
Local $aContent = _FileListToArray($sPath, "*.*", 1), $cItem
If IsArray($aContent) Then
For $i = 1 To $aContent[0]
$cItem = GUICtrlCreateTreeViewItem($aContent[$i], $cParent)
GUICtrlSetColor($cItem, 0x0000FF)
Next
EndIf
$aContent = _FileListToArray($sPath, "*", 2)
If IsArray($aContent) Then
For $i = 1 To $aContent[0]
$cItem = GUICtrlCreateTreeViewItem($aContent[$i] & "", $cParent)
GUICtrlSetColor($cItem, 0xFF0000)
Next
EndIf
EndFunc

Any use? :)

M23

Exactly what I needed!

Thanks for the input, I'm sure I can extract some knowledge from it.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...