private bool AutoCheckExplorerTreeNode(ExplorerTreeNode explorerTreeNode)
        {
            bool returnValue;

            switch (explorerTreeNode.NodeType)
            {
            case ExplorerTreeNodeType.Directory:
            {
                returnValue = AutoCheckDirectory(explorerTreeNode.Name);
                break;
            }

            case ExplorerTreeNodeType.File:
            {
                returnValue = AutoCheckFile(explorerTreeNode.Name);
                break;
            }

            default:
            {
                returnValue = false;
                break;
            }
            }

            return(returnValue);
        }
        private void ExplorerTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            ExplorerTreeNode node = e.Node as ExplorerTreeNode;

            if (node != null)
            {
                PopulateNode(ref node);
            }
        }
        private ExplorerTreeNode CreateNode(string path)
        {
            ExplorerTreeNode treeNode = new ExplorerTreeNode(path)
            {
                ImageIndex         = GetImageIndex(path),
                SelectedImageIndex = GetImageIndex(path),
            };

            if (treeNode.NodeType == ExplorerTreeNodeType.Directory)
            {
                treeNode.Nodes.Add(new ExplorerTreeNode());
            }

            return(treeNode);
        }
        private List <ExplorerTreeNode> GetFileNodes(string folder)
        {
            List <ExplorerTreeNode> returnValue = new List <ExplorerTreeNode>();

            foreach (string file in Directory.GetFiles(folder, "*", SearchOption.TopDirectoryOnly))
            {
                ExplorerTreeNode fileNode = CreateNode(file);

                if (fileNode != null)
                {
                    returnValue.Add(fileNode);
                }
            }

            return(returnValue);
        }
        private void ExplorerTreeView_AfterCheck(object sender, TreeViewEventArgs e)
        {
            ExplorerTreeNode explorerTreeNode = e.Node as ExplorerTreeNode;

            if (explorerTreeNode != null)
            {
                if (!explorerTreeNode.Checked)
                {
                    UncheckNodes(explorerTreeNode);
                }
                else if (AutoCheck)
                {
                    CheckNodes(explorerTreeNode);
                }
            }
        }
        private List <ExplorerTreeNode> GetDirectoryNodes(string folder)
        {
            List <ExplorerTreeNode> returnValue = new List <ExplorerTreeNode>();

            foreach (string directory in Directory.GetDirectories(folder, "*", SearchOption.TopDirectoryOnly))
            {
                ExplorerTreeNode directoryNode = CreateNode(directory);

                if (directoryNode != null)
                {
                    if (AutoPopulate)
                    {
                        PopulateNode(ref directoryNode);
                    }

                    returnValue.Add(directoryNode);
                }
            }

            return(returnValue);
        }
        private void PopulateNode(ref ExplorerTreeNode node)
        {
            if (node.Nodes.Count <= 1)
            {
                node.Nodes.Clear();

                List <ExplorerTreeNode> directoryNodes = GetDirectoryNodes(node.FullName);
                List <ExplorerTreeNode> fileNodes      = GetFileNodes(node.FullName);

                if (directoryNodes.Count > 0)
                {
                    node.Nodes.AddRange(directoryNodes.ToArray());
                }

                if (fileNodes.Count > 0)
                {
                    node.Nodes.AddRange(fileNodes.ToArray());
                }
            }

            Application.DoEvents(); // TODO: Not sure if this is necessary
        }
        private void UpdateRootPath(string rootPath)
        {
            if (Directory.Exists(rootPath))
            {
                _RootPath = rootPath;

                Nodes.Clear();


                ExplorerTreeNode rootNode = new ExplorerTreeNode(rootPath)
                {
                    ImageIndex         = GetImageIndex(rootPath),
                    SelectedImageIndex = GetImageIndex(rootPath),
                    Text        = rootPath,
                    ToolTipText = rootPath,
                };

                PopulateNode(ref rootNode);
                Nodes.Add(rootNode);
                rootNode.Checked = AutoCheck;
                rootNode.Expand();
            }
        }