Big, big thank you musefan and Ian! I’ve now got it working brilliantly. Based on the pseudo-code Ian posted (which worked great after tweeking!) I’ve decided to post the working code incase anyone else out there is experiencing TreeNode’s from hell lol. "ps, i'm not great with codeproject, so if you know of a better place for me to post this answer, please let me know." Well here’s the working code… :-D :thumbsup: Add a TreeView control to Form1 and name it treeView1. and then add this code.. private void Form1_Load(object sender, EventArgs e) { TreeNode tn = new TreeNode("Root"); // set PathSeparator to url paths treeView1.PathSeparator = "/"; // Create any old folders and process InsertURL(tn, @"mywebsite.com/home/about_us.aspx"); InsertURL(tn, @"mywebsite.com/home/contact_us.aspx"); InsertURL(tn, @"mywebsite.com/home/main.aspx"); InsertURL(tn, @"mywebsite.com/blogs/seo.aspx"); InsertURL(tn, @"mywebsite.com/blogs/linkchecks.aspx"); InsertURL(tn, @"mywebsite.com/blogs/howto/gettheresults.aspx"); //add nodes to treeView treeView1.Nodes.Add(tn); } private void InsertURL(TreeNode root, string url) { InsertURL(root, SplitNodes(url), 0); } private string[] SplitNodes(string nodeString) { char[] delimiter = treeView1.PathSeparator.ToCharArray(); return nodeString.Split(delimiter, StringSplitOptions.RemoveEmptyEntries); } private void InsertURL(TreeNode parent, string[] urlParts, int index) { // Create the node if it doesn't exist. CreateNode(parent, urlParts[index]); // get the next urlPart index++; if (index < urlParts.Length) { InsertURL(parent.Nodes[urlParts[index-1]], urlParts, index); } } private static void CreateNode(TreeNode treeNode, string name) { // Add the node if it don't exist if (treeNode.Nodes[name] == null) { treeNode.Nodes.Add(name, name); } }
modified on Saturday, March 28, 2009 5:57 AM