资源简介

TreeView和ListView控件联动事例。源代码事例,TreeView不同事件下触发并载ICO,动态显示效果。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SecureTree
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            //实例化TreeNode类 TreeNode(string textint imageIndexint selectImageIndex)            
            TreeNode rootNode = new TreeNode(“我的电脑“
                IconIndexes.MyComputer IconIndexes.MyComputer);  //载入显示 选择显示
            rootNode.Tag = “我的电脑“;                            //树节点数据
            rootNode.Text = “我的电脑“;                           //树节点标签内容
            this.directoryTree.Nodes.Add(rootNode);               //树中添加根目录

            //显示MyDocuments(我的文档)结点
            var myDocuments = Environment.GetFolderPath           //获取计算机我的文档文件夹
                (Environment.SpecialFolder.MyDocuments);
            TreeNode DocNode = new TreeNode(myDocuments);
            DocNode.Tag = “我的文档“;                            //设置结点名称
            DocNode.Text = “我的文档“;
            DocNode.ImageIndex = IconIndexes.MyDocuments;         //设置获取结点显示图片
            DocNode.SelectedImageIndex = IconIndexes.MyDocuments; //设置选择显示图片
            rootNode.Nodes.Add(DocNode);                          //rootNode目录下加载节点
            DocNode.Nodes.Add(““);

            //循环遍历计算机所有逻辑驱动器名称(盘符)
            foreach (string drive in Environment.GetLogicalDrives())
            {
                //实例化DriveInfo对象 命名空间System.IO
                var dir = new DriveInfo(drive);
                switch (dir.DriveType)           //判断驱动器类型
                {
                    case DriveType.Fixed:        //仅取固定磁盘盘符 Removable-U盘 
                        {
                            //Split仅获取盘符字母
                            TreeNode tNode = new TreeNode(dir.Name.Split(‘:‘)[0]);
                            tNode.Name = dir.Name;
                            tNode.Tag = tNode.Name;
                            tNode.ImageIndex = IconIndexes.FixedDrive;         //获取结点显示图片
                            tNode.SelectedImageIndex = IconIndexes.FixedDrive; //选择显示图片
                            directoryTree.Nodes.Add(tNode);                    //加载驱动节点
                            tNode.Nodes.Add(““);
                        }
                        break;
                }
            }
            SetListView();
        }

        private void directoryTree_AfterExpand(object sender TreeViewEventArgs e)
        {
            e.Node.Expand();
        }

        private void directoryTree_BeforeExpand(object sender TreeViewCancelEventArgs e)
        {
            TreeViewItems.Add(e.Node);
        }

        /// 

        /// 自定义类TreeViewItems 调用其Add(TreeNode e)方法加

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     44032  2019-02-15 12:55  SecureTree\.vs\SecureTree\v14\.suo

     文件        189  2019-02-15 09:41  SecureTree\SecureTree\App.config

     文件      19968  2019-02-15 12:52  SecureTree\SecureTree\bin\Debug\SecureTree.exe

     文件        189  2019-02-15 09:41  SecureTree\SecureTree\bin\Debug\SecureTree.exe.config

     文件      24064  2019-02-15 12:52  SecureTree\SecureTree\bin\Debug\SecureTree.pdb

     文件      22696  2019-02-15 12:55  SecureTree\SecureTree\bin\Debug\SecureTree.vshost.exe

     文件        189  2019-02-15 09:41  SecureTree\SecureTree\bin\Debug\SecureTree.vshost.exe.config

     文件        490  2018-04-12 07:35  SecureTree\SecureTree\bin\Debug\SecureTree.vshost.exe.manifest

     文件      10645  2019-02-15 12:52  SecureTree\SecureTree\Form1.cs

     文件       4732  2019-02-15 12:52  SecureTree\SecureTree\Form1.Designer.cs

     文件      16818  2019-02-15 12:52  SecureTree\SecureTree\Form1.resx

     文件        614  2019-02-15 12:10  SecureTree\SecureTree\IconIndexes.cs

     文件        868  2019-02-15 09:41  SecureTree\SecureTree\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7180  2019-02-15 12:08  SecureTree\SecureTree\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        648  2019-02-15 12:55  SecureTree\SecureTree\obj\Debug\SecureTree.csproj.FileListAbsolute.txt

     文件       1012  2019-02-15 12:52  SecureTree\SecureTree\obj\Debug\SecureTree.csproj.GenerateResource.Cache

     文件      19968  2019-02-15 12:52  SecureTree\SecureTree\obj\Debug\SecureTree.exe

     文件       7304  2019-02-15 12:52  SecureTree\SecureTree\obj\Debug\SecureTree.Form1.resources

     文件      24064  2019-02-15 12:52  SecureTree\SecureTree\obj\Debug\SecureTree.pdb

     文件        180  2019-02-15 12:52  SecureTree\SecureTree\obj\Debug\SecureTree.Properties.Resources.resources

     文件          0  2019-02-15 09:41  SecureTree\SecureTree\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2019-02-15 09:41  SecureTree\SecureTree\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2019-02-15 09:41  SecureTree\SecureTree\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件        522  2019-02-15 09:41  SecureTree\SecureTree\Program.cs

     文件       1328  2019-02-15 09:41  SecureTree\SecureTree\Properties\AssemblyInfo.cs

     文件       2833  2019-02-15 09:41  SecureTree\SecureTree\Properties\Resources.Designer.cs

     文件       5612  2019-02-15 09:41  SecureTree\SecureTree\Properties\Resources.resx

     文件       1097  2019-02-15 09:41  SecureTree\SecureTree\Properties\Settings.Designer.cs

     文件        249  2019-02-15 09:41  SecureTree\SecureTree\Properties\Settings.settings

     文件       3960  2019-02-15 12:10  SecureTree\SecureTree\SecureTree.csproj

............此处省略16个文件信息

评论

共有 条评论