Beispiel #1
0
        /// <summary>
        /// Adds the desktop node.
        /// </summary>
        public static void AddDesktopNode(this ShellTreeView tree)
        {
            //  Get the desktop folder.
            var desktopFolder = ShellItem.DesktopShellFolder;

            //  Create the desktop node.
            var desktopNode = new TreeNode
            {
                Text               = desktopFolder.DisplayName,
                ImageIndex         = desktopFolder.IconIndex,
                SelectedImageIndex = desktopFolder.IconIndex,
            };

            //  Map it and add it.
            tree.NodesToFolders[desktopNode] = desktopFolder;
            tree.ShowRootLines = false;
            tree.Nodes.Add(desktopNode);

            //  Fire the event.
            tree.FireOnShellItemAdded(desktopNode);

            //  Expand it.
            //OnBeforeExpand(new TreeViewCancelEventArgs(desktopNode, false, TreeViewAction.Expand));
            DoExpand(tree, desktopNode);
            desktopNode.Expand();
        }
Beispiel #2
0
        public static void DoExpand(this ShellTreeView tree, TreeNode node)
        {
            //  Clear children - which may in fact be the placeholder.
            node.Nodes.Clear();
            var nodesToFolders = tree.NodesToFolders;

            //  Get the shell folder.
            ShellItem shellFolder = nodesToFolders[node];

            //  Create the enum flags.
            ChildTypes childFlags = ChildTypes.Folders;

            if (tree.ShowFiles)
            {
                childFlags |= ChildTypes.Files;
            }
            if (tree.ShowHiddenFilesAndFolders)
            {
                childFlags |= ChildTypes.Hidden;
            }

            //  Disable update while adding children.
            tree.BeginUpdate();

            int count = 0;

            try
            {
                //  Go through each child.
                foreach (var childNode in
                         EnumerateUnsafe(shellFolder, childFlags, node, nodesToFolders))
                {
                    count++;
                    //  Fire the shell item added event.
                    tree.FireOnShellItemAdded(childNode);
                }

                if (count == 0)
                {
                    childFlags = ChildTypes.Files | ChildTypes.Hidden;

                    foreach (var childNode in
                             EnumerateUnsafe(shellFolder, childFlags, node, nodesToFolders))
                    {
                        count++;
                        //  Fire the shell item added event.
                        tree.FireOnShellItemAdded(childNode);
                    }
                    if (count > 0)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                MessageBox.Show(ex.Message);
            }

            //  Enable update now that we've added the children.
            tree.EndUpdate();
        }