/// <summary>Populate the directory tree</summary> private void SetupTree() { // Sort directories alphabetically m_tree.TreeViewNodeSorter = Cmp <TreeNode> .From((l, r) => string.Compare(l.Name, r.Name)); // Dynamically add sub directory nodes as needed m_tree.NodesNeeded += (s, a) => { if (a.Node.Nodes.Count != 0) { return; } PopulateChildNodes(a.Node); }; // Populate the tree with the drives foreach (var dv in DriveInfo.GetDrives()) { if (!dv.IsReady) { continue; } var drive = dv.Name.TrimEnd('\\'); var node = new TreeNode(drive, TreeNode.ETriState.Unchecked); m_tree.Nodes.Add(node); PopulateChildNodes(node); } // Checking a node adds or removes that path from the list m_tree.AfterCheck += (s, a) => { if (m_updating_check_marks != null) { return; } // Add or remove the path var path = new Path(a.Node.FullPath); if (a.Node.Checked) { Paths.AddOrdered(path, Path.Compare); } else { // If 'path' is in the list, then the ListChanging handler will call HandlePathRemoved // If not in the list, then we need to call it explicitly if (!Paths.Remove(path)) { HandlePathRemoved(path); } } }; }