I'm trying to build a TreeView from a flat list of files like this:
Code: Select all
X:\Folder5\Folder9\SomeFile5.txt
X:\Folder5\Folder6\Folder7\Folder8\SomeFile4.txt
E:\Folder1\Folder4\SomeFile3.txt
E:\Folder1\Folder2\SomeFile2.txt
E:\Folder1\Folder2\Folder3\SomeFile1.txt
I can't enumerate the files/folders because they don't necessarily exist. My data comes from a database in that format.
The data contains only files, no folders, and can be large (up to tens of thousands of entries), but is usually very small (dozens of entries), so inefficient/suboptimal solutions are ok.
The data is sorted (and I can have it reversed for free, if needed). I'm using it reversed in my example because my code was showing the results reversed.
Any help is greatly appreciated.
I'm pasting the code below, so it can easily be checked.
Here's how it looks. Notice that X:\Folder5\Folder9 is not a child of a parent X:\Folder5, same for E:\Folder1\Folde4 and E:\Folder1\Folder2, but, E:\Folder1\Folder2\Folder3 is properly parented.
What is happening is that I can't figure out a way to create items in the TreeView for all sub-paths of the given path. I can see when I call TV_Add for the folders that I'm not handling all cases.
I've tried quite a few ideas, so maybe I got blinded.
Code: Select all
Removed to avoid confusion with users searching for this.
See accepted answer. It's perfect.