Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to update my old source code to UWP referencing Microsoft.UI.Xaml.dll TreeView control to display/replicate files and folders stored in a string[].

string[] stores the complete paths to one or more files.

Example:

C:\Users\User\Documents\Test1.txt

C:\Users\User\Documents\Test2.txt

C:\Users\User\Documents\folder\Test1.txt

C:\Users\User\Documents\folder\Test2.txt

The code that I would like to update is the following:

C#
private void PopulateTreeView(TreeView treeView, string[] paths, char pathSeparator)
        {
            TreeNode lastNode = null;
            string subPathAgg;
            long count = 0;

            foreach (string path in paths)
            {
                subPathAgg = string.Empty;
                foreach (string subPath in path.Split(pathSeparator))
                {
                    Application.DoEvents();
                    subPathAgg += subPath + pathSeparator;
                    TreeNode[] nodes = treeView.Nodes.Find(subPathAgg, true);
                    if (nodes.Length == 0)
                    {
                        if (lastNode == null)
                        {
                            lastNode = treeView.Nodes.Add(subPathAgg, subPath);
                        }
                        else
                        {
                            lastNode = lastNode.Nodes.Add(subPathAgg, subPath);
                        }
                        count++;
                    }
                    else
                    {
                        lastNode = nodes[0];
                    }
                }
                lastNode = null; // This is the place code was changed
            }
        }

Does anyone know how to update this code using Microsoft.UI.Xaml.dll TreeView control? I thought this should be easy, but I feel like I've missed something.

What I have tried:

Tried to google references on Microsoft.UI.Xaml.dll TreeView control but couldn't find any examples related to displaying files/folders from a string array.
Posted
Updated 21-Nov-19 18:45pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900