Example #1
0
        private TreeNode MakeNode(CShItem item)
        {
            TreeNode newNode = new TreeNode(item.DisplayName);

            newNode.Tag                = item;
            newNode.ImageIndex         = SystemImageListManager.GetIconIndex(item, false, false);
            newNode.SelectedImageIndex = SystemImageListManager.GetIconIndex(item, true, false);
            //The following code, from Calum implements the following logic
            // Allow/disallow the showing of Hidden folders based on ShowHidden Propert
            // For Removable disks, always show + (allow expansion) - avoids floppy access
            // For all others, add + based on HasSubFolders
            //  Except - If showing Hidden dirs, do extra check to  allow for
            //  the case of all hidden items in the Dir which will cause
            //  HasSubFolders to be always left unset
            if (item.IsRemovable)             //Calum's fix to hidden file fix
            {
                newNode.Nodes.Add(new TreeNode(" : "));
            }
            else if (item.HasSubFolders)
            {
                newNode.Nodes.Add(new TreeNode(" : "));
                //Begin Calum's change so Hidden dirs with all hidden content are expandable
            }
            else if (item.GetDirectories(true).Count > 0)             //Added Code
            {
                newNode.Nodes.Add(new TreeNode(" : "));               //Added Code
                //End Calum's change
            }
            return(newNode);
        }
Example #2
0
        private void OnStartUpDirectoryChanged(StartDir newVal)
        {
            if (Root != null)
            {
                ClearTree();
            }
            CShItem special;

            special                 = ExpTreeLib.CShItem.GetCShItem((ShellDll.CSIDL)(int)(m_StartUpDirectory));
            Root                    = new TreeNode(special.DisplayName);
            Root.ImageIndex         = SystemImageListManager.GetIconIndex(special, false, false);
            Root.SelectedImageIndex = Root.ImageIndex;
            Root.Tag                = special;
            BuildTree(special.GetDirectories(true));
            tv1.Nodes.Add(Root);
            Root.Expand();
        }
Example #3
0
 ///<Summary>When a form containing this control is Hidden and then re-Shown,
 /// the association to the SystemImageList is lost.  Also lost is the
 /// Expanded state of the various TreeNodes.
 /// The VisibleChanged Event occurs when the form is re-shown (and other times
 ///  as well).
 /// We re-establish the SystemImageList as the ImageList for the TreeView and
 /// restore at least some of the Expansion.</Summary>
 private void tv1_VisibleChanged(object sender, System.EventArgs e)
 {
     if (tv1.Visible)
     {
         SystemImageListManager.SetTreeViewImageList(tv1, false);
         if (Root != null)
         {
             Root.Expand();
             if (tv1.SelectedNode != null)
             {
                 tv1.SelectedNode.Expand();
             }
             else
             {
                 tv1.SelectedNode = this.Root;
             }
         }
     }
 }
Example #4
0
        public ExpTree()
        {
            //This call is required by the Windows Form Designer.
            InitializeComponent();

            //Add any initialization after the InitializeComponent() call


            //setting the imagelist here allows many good things to happen, but
            // also one bad thing -- the "tooltip" like display of selectednode.text
            // is made invisible.  This remains a problem to be solved.
            SystemImageListManager.SetTreeViewImageList(tv1, false);

            StartUpDirectoryChanged += new ExpTreeLib.ExpTree.StartUpDirectoryChangedEventHandler(OnStartUpDirectoryChanged);

            OnStartUpDirectoryChanged(m_StartUpDirectory);

            if (tv1.IsHandleCreated)
            {
                if (this.AllowDrop)
                {
                    if (Application.OleRequired() == System.Threading.ApartmentState.STA)
                    {
                        DragDropHandler              = new TVDragWrapper(tv1);
                        DragDropHandler.ShDragEnter += new ExpTreeLib.TVDragWrapper.ShDragEnterEventHandler(DragWrapper_ShDragEnter);
                        DragDropHandler.ShDragLeave += new ExpTreeLib.TVDragWrapper.ShDragLeaveEventHandler(DragWrapper_ShDragLeave);
                        DragDropHandler.ShDragOver  += new ExpTreeLib.TVDragWrapper.ShDragOverEventHandler(DragWrapper_ShDragOver);
                        DragDropHandler.ShDragDrop  += new ExpTreeLib.TVDragWrapper.ShDragDropEventHandler(DragWrapper_ShDragDrop);
                        int res;
                        res = ShellDll.RegisterDragDrop(tv1.Handle, DragDropHandler);
                        if (!(res == 0) || (res == -2147221247))
                        {
                            Marshal.ThrowExceptionForHR(res);
                            throw (new Exception("Failed to Register DragDrop for " + this.Name));
                        }
                    }
                    else
                    {
                        throw (new ThreadStateException("ThreadMustBeSTA"));
                    }
                }
            }
        }