AndrewG Posted April 1, 2009 Share Posted April 1, 2009 I'm in Treeview control hell. I have a Treeview control that gets populated with folders and the contents of each folder that are located in the script dir. I want to get the file path of a selected item. I'm using GUICtrlSetOnEvent() to call a function _Show() to read the control but no luck. I can't even get the function _Show() to execute and create a MsgBox(). Would somebody please help me out of this hell! expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> #include <File.au3> #include <TreeviewConstants.au3> #Include <GuiTreeView.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $frmMain = GUICreate("Learning Treeview", 800, 480, (@DesktopWidth - 800)/2, (@DesktopHeight - 480)/2, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp") Global $frmMainFileMenu = GUICtrlCreateMenu("File") Global $frmMainFileMenu_Exit = GUICtrlCreateMenuItem("Exit", $frmMainFileMenu) GUICtrlSetOnEvent($frmMainFileMenu_Exit, "ExitApp") Global $frmMain_FileTree = GUICtrlCreateTreeView(10, 20, 150, 330, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) Global $i, $iF, $aFiles, $aDirectorys, $aDirNames, $aFileNames ;Get all directorys in script directory $aDirectorys = _FileListToArray(@ScriptDir, '*.*', 2) _ArrayDelete($aDirectorys, 0) ;Loop through returned array and add directorys to treeview For $i = 0 To UBound($aDirectorys) -1 $aDirNames = GUICtrlCreateTreeViewItem($aDirectorys[$i],$frmMain_FileTree) ;Get files in each folder $aFiles = _FileListToArray($aDirectorys[$i], "*", 1) _ArrayDelete($aFiles, 0) ;_ArrayDisplay($aFiles) ;Loop through returned file names and add file name to each directory For $iF = 0 To UBound($aFiles) -1 $aFileNames = GUICtrlCreateTreeViewItem($aFiles[$iF],$aDirNames) Next Next GUICtrlSetOnEvent($frmMain_FileTree, "_Show") GUISetState(@SW_SHOW) While 1 sleep(1000) WEnd Func ExitApp() Exit EndFunc Func _Show() MsgBox(0, "", GUICtrlRead($frmMain_FileTree, 0)) ;MsgBox(0,"", _GUICtrlTreeView_GetText($frmMain_FileTree)) ;MsgBox(0,"", $frmMain_FileTree) ;MsgBox(0, "", "Working") EndFunc Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 1, 2009 Share Posted April 1, 2009 I believe the GUICtrlSetOnEvent needs to be applied to the TreeViewItem rather than the TreeView itself. Try: ... $aDirNames = GUICtrlCreateTreeViewItem($aDirectorys[$i],$frmMain_FileTree) GUICtrlSetOnEvent($aDirNames, "_Show") ... $aFileNames = GUICtrlCreateTreeViewItem($aFiles[$iF],$aDirNames) GUICtrlSetOnEvent($aFileNames, "_Show") ... I guess you'll also be using _GUICtrlTreeView_GetTree() ? WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
Nahuel Posted April 2, 2009 Share Posted April 2, 2009 Look at the comments I made in the code. expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> #include <File.au3> #include <TreeviewConstants.au3> #Include <GuiTreeView.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $frmMain = GUICreate("Learning Treeview", 800, 480, (@DesktopWidth - 800)/2, (@DesktopHeight - 480)/2, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp") Global $frmMainFileMenu = GUICtrlCreateMenu("File") Global $frmMainFileMenu_Exit = GUICtrlCreateMenuItem("Exit", $frmMainFileMenu) GUICtrlSetOnEvent($frmMainFileMenu_Exit, "ExitApp") Global $frmMain_FileTree = GUICtrlCreateTreeView(10, 20, 150, 330, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) Global $i, $iF, $aFiles, $aDirectorys, $aDirNames, $aFileNames ;Get all directorys in script directory $aDirectorys = _FileListToArray(@ScriptDir, '*.*', 2) _ArrayDelete($aDirectorys, 0) ;Loop through returned array and add directorys to treeview For $i = 0 To UBound($aDirectorys) -1 $aDirNames = GUICtrlCreateTreeViewItem($aDirectorys[$i],$frmMain_FileTree) GUICtrlSetOnEvent(-1,"_Show");------>HERE ;Get files in each folder $aFiles = _FileListToArray($aDirectorys[$i], "*", 1) _ArrayDelete($aFiles, 0) ;_ArrayDisplay($aFiles) ;Loop through returned file names and add file name to each directory For $iF = 0 To UBound($aFiles) -1 $aFileNames = GUICtrlCreateTreeViewItem($aFiles[$iF],$aDirNames) GUICtrlSetOnEvent(-1,"_Show");------>HERE Next Next ;GUICtrlSetOnEvent($frmMain_FileTree, "_Show")->WRONG GUISetState(@SW_SHOW) While 1 sleep(1000) WEnd Func ExitApp() Exit EndFunc Func _Show() MsgBox(0,"",GUICtrlRead(@GUI_CtrlId,1)) ;MsgBox(0, "", GUICtrlRead($frmMain_FileTree, 0)) ;MsgBox(0,"", _GUICtrlTreeView_GetText($frmMain_FileTree)) ;MsgBox(0,"", $frmMain_FileTree) ;MsgBox(0, "", "Working") EndFunc Link to comment Share on other sites More sharing options...
AndrewG Posted April 2, 2009 Author Share Posted April 2, 2009 (edited) I believe the GUICtrlSetOnEvent needs to be applied to the TreeViewItem rather than the TreeView itself. Try: ... $aDirNames = GUICtrlCreateTreeViewItem($aDirectorys[$i],$frmMain_FileTree) GUICtrlSetOnEvent($aDirNames, "_Show") ... $aFileNames = GUICtrlCreateTreeViewItem($aFiles[$iF],$aDirNames) GUICtrlSetOnEvent($aFileNames, "_Show") ... I guess you'll also be using _GUICtrlTreeView_GetTree() ? WBD Thank you. That Solved my issue. I just checked out _GUICtrlTreeView_GetTree(), and yes I will be using that as well. Thanks. Edited April 2, 2009 by AndrewG Link to comment Share on other sites More sharing options...
AndrewG Posted April 2, 2009 Author Share Posted April 2, 2009 (edited) Look at the comments I made in the code. expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> #include <File.au3> #include <TreeviewConstants.au3> #Include <GuiTreeView.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $frmMain = GUICreate("Learning Treeview", 800, 480, (@DesktopWidth - 800)/2, (@DesktopHeight - 480)/2, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp") Global $frmMainFileMenu = GUICtrlCreateMenu("File") Global $frmMainFileMenu_Exit = GUICtrlCreateMenuItem("Exit", $frmMainFileMenu) GUICtrlSetOnEvent($frmMainFileMenu_Exit, "ExitApp") Global $frmMain_FileTree = GUICtrlCreateTreeView(10, 20, 150, 330, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) Global $i, $iF, $aFiles, $aDirectorys, $aDirNames, $aFileNames ;Get all directorys in script directory $aDirectorys = _FileListToArray(@ScriptDir, '*.*', 2) _ArrayDelete($aDirectorys, 0) ;Loop through returned array and add directorys to treeview For $i = 0 To UBound($aDirectorys) -1 $aDirNames = GUICtrlCreateTreeViewItem($aDirectorys[$i],$frmMain_FileTree) GUICtrlSetOnEvent(-1,"_Show");------>HERE ;Get files in each folder $aFiles = _FileListToArray($aDirectorys[$i], "*", 1) _ArrayDelete($aFiles, 0) ;_ArrayDisplay($aFiles) ;Loop through returned file names and add file name to each directory For $iF = 0 To UBound($aFiles) -1 $aFileNames = GUICtrlCreateTreeViewItem($aFiles[$iF],$aDirNames) GUICtrlSetOnEvent(-1,"_Show");------>HERE Next Next ;GUICtrlSetOnEvent($frmMain_FileTree, "_Show")->WRONG GUISetState(@SW_SHOW) While 1 sleep(1000) WEnd Func ExitApp() Exit EndFunc Func _Show() MsgBox(0,"",GUICtrlRead(@GUI_CtrlId,1)) ;MsgBox(0, "", GUICtrlRead($frmMain_FileTree, 0)) ;MsgBox(0,"", _GUICtrlTreeView_GetText($frmMain_FileTree)) ;MsgBox(0,"", $frmMain_FileTree) ;MsgBox(0, "", "Working") EndFunc Thank you. That solved my issue. Edited April 2, 2009 by AndrewG Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now