I'm new in PurBasic but have some experience with TurboBasic long time ago

After extensive search on the forum without success I would like to point out my problem.
Short description on my problem:
I code a software for reading manuals. These are stored in folders and subfolders (pdf-files). I do not want to use the ExplorerTree because the user should only search in the allowed tree-structure on the CD.
What I have done:
I tried to list all folders in a Treeview Gadget (only folders and subfolders should be in this) and on selection on a specific folder another Listview shows the files. (not coded)
Problem in code:
The only problem is that with the code only the first subfolder comes into the treeview. But i need the complete tree structure like in Explorertree. And if I filter all the files I only get the first folder of the tree.

The code is from some samples I only modified it.
I would be very glad for some hints to solve my problem.

Code: Select all
DirectoryName.s
#WindowWidth = 640
#WindowHeight = 480
LoadImage(0, "img0.png")
LoadImage(1, "img1.png")
Procedure ListFiles(EntryPath.s)
EntryPath + "\"
UsedDirectory = ExamineDirectory(#PB_Any, EntryPath, "*.*")
While NextDirectoryEntry(UsedDirectory)
EntryType.l = DirectoryEntryType(UsedDirectory)
EntryName.s = DirectoryEntryName(UsedDirectory)
If EntryName = "." Or EntryName = "..": Continue: EndIf
If EntryType = #PB_DirectoryEntry_File
NDir$=EntryPath+EntryName
AddGadgetItem(2, -1, DirectoryEntryName(UsedDirectory) , ImageID(1),1)
EndIf
If EntryType = #PB_DirectoryEntry_Directory
Level=0 ; test to try different levels
ListFiles(EntryPath + EntryName)
AddGadgetItem(2, -1, DirectoryEntryName(UsedDirectory) , ImageID(3),Level)
Level=0
EndIf
Wend: FinishDirectory(UsedDirectory)
EndProcedure
If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Tree structure", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
TreeGadget (2, 10, 50, 550, 400)
;SetGadgetText(4, "Initialize Ok... Welcome !")
; Fill Up the Tree gadget with Folders
DirectoryName = PathRequester("Please choose a folder...", "")
ListFiles(DirectoryName)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
Select EventGadget()
Case 1
MessageRequester("Information", "You did it !", 0)
Case 2
SetGadgetText(4, "Tree Gadget. Item selected: "+Str(GetGadgetState(2)))
If EventType() = 2
MessageRequester("Information", "Doubleclick: item"+Str(GetGadgetState(2))+", Text: "+GetGadgetText(2), 0)
ElseIf EventType() = 1
DisplayPopupMenu(0, WindowID(0))
EndIf
Case 5
SetGadgetText(4, "ListIcon Gadget. Item selected: "+Str(GetGadgetState(5)))
If EventType() = 2
MessageRequester("Information", "Doubleclick: item"+Str(GetGadgetState(5))+", Text: "+GetGadgetText(5), 0)
ElseIf EventType() = 1
DisplayPopupMenu(0, WindowID(0))
EndIf
EndSelect
EndIf
Until EventID = #PB_Event_CloseWindow
EndIf
End