• 大小: 394KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: C#
  • 标签: TreeListView  

资源简介

C# WinForm TreeListView控件用法初步

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

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

        private void Form1_Load(object sender EventArgs e)
        {
            AddItems();
        }
        private void AddItems()
        {
            //第一个参数是要显示的文本,第二个参数是要显示的图标索引。
            TreeListViewItem itemA = new TreeListViewItem(“A“ 0);
            itemA.Expand();//展开
            itemA.SubItems.Add(“AA“);//SubItems相当于同一行的不同列值。
            itemA.SubItems.Add(“BB“);//第三列
            //二级
            TreeListViewItem itemA0 = new TreeListViewItem(“A0“ 1);
            itemA.Items.Add(itemA0);
            //三级
            TreeListViewItem itemA00 = new TreeListViewItem(“A00“ 3);
            itemA0.Items.Add(itemA00);

            treeListView1.Items.Add(itemA);
        }
        //折叠事件
        private void treeListView1_BeforeCollapse(object sender TreeListViewCancelEventArgs e)
        {
            //索引12分别对应折叠与展开的图标。
            if (e.Item.ImageIndex == 2) e.Item.ImageIndex = 1;
        }
        //展开事件
        private void treeListView1_BeforeExpand(object sender TreeListViewCancelEventArgs e)
        {
            if (e.Item.ImageIndex == 1) e.Item.ImageIndex = 2;
        }
        //编辑状态
        private void treeListView1_BeforeLabelEdit(object sender TreeListViewBeforeLabelEditEventArgs e)
        {
            //设置LabelEdit属性为True才可激活
            if (e.Item.ImageIndex < 1 || e.Item.ImageIndex > 2)//第一级与第三级只可以编辑第一列。
                e.ColumnIndex = 0;
            if (e.ColumnIndex == 1)//如果是第二列,显示一个下拉框。
            {
                ComboBox combobox = new ComboBox();
                combobox.Items.AddRange(new string[] { “New value 1“ “New value 2“ “New value 3“ });
                e.Editor = combobox;
            }
        }
    }
}

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

     文件        249  2010-10-20 17:12  TreeListViewApp\TreeListViewApp\Properties\Settings.settings

     文件       1196  2010-10-20 17:12  TreeListViewApp\TreeListViewApp\Properties\AssemblyInfo.cs

     文件       5612  2010-10-20 17:12  TreeListViewApp\TreeListViewApp\Properties\Resources.resx

     文件       2854  2010-10-20 17:18  TreeListViewApp\TreeListViewApp\Properties\Resources.Designer.cs

     文件       1113  2010-10-20 17:18  TreeListViewApp\TreeListViewApp\Properties\Settings.Designer.cs

     文件       3898  2010-10-21 09:19  TreeListViewApp\TreeListViewApp\TreeListViewApp.csproj

     文件       5632  2005-12-08 14:51  TreeListViewApp\TreeListViewApp\bin\Debug\TreeListViewApp.vshost.exe

     文件      69632  2010-10-20 16:02  TreeListViewApp\TreeListViewApp\bin\Debug\System.Windows.Forms.TreeListView.dll

     文件      81920  2010-10-20 16:00  TreeListViewApp\TreeListViewApp\bin\Debug\System.Runtime.InteropServices.APIs.dll

     文件     128512  2010-10-20 16:02  TreeListViewApp\TreeListViewApp\bin\Debug\System.Windows.Forms.TreeListView.pdb

     文件      50751  2010-10-20 16:02  TreeListViewApp\TreeListViewApp\bin\Debug\System.Windows.Forms.TreeListView.xml

     文件      50688  2010-10-20 16:00  TreeListViewApp\TreeListViewApp\bin\Debug\System.Runtime.InteropServices.APIs.pdb

     文件      32427  2010-10-20 16:00  TreeListViewApp\TreeListViewApp\bin\Debug\System.Runtime.InteropServices.APIs.xml

     文件      24576  2010-10-21 09:39  TreeListViewApp\TreeListViewApp\bin\Debug\TreeListViewApp.exe

     文件      26112  2010-10-21 09:39  TreeListViewApp\TreeListViewApp\bin\Debug\TreeListViewApp.pdb

     文件       4608  2010-10-20 17:18  TreeListViewApp\TreeListViewApp\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       7657  2010-10-21 09:05  TreeListViewApp\TreeListViewApp\obj\Debug\ResolveAssemblyReference.cache

     文件       3023  2010-10-21 09:36  TreeListViewApp\TreeListViewApp\obj\Debug\TreeListViewApp.Form1.resources

     文件        180  2010-10-21 09:05  TreeListViewApp\TreeListViewApp\obj\Debug\TreeListViewApp.Properties.Resources.resources

     文件      26112  2010-10-21 09:39  TreeListViewApp\TreeListViewApp\obj\Debug\TreeListViewApp.pdb

     文件      24576  2010-10-21 09:39  TreeListViewApp\TreeListViewApp\obj\Debug\TreeListViewApp.exe

     文件        842  2010-10-21 09:36  TreeListViewApp\TreeListViewApp\obj\Debug\TreeListViewApp.csproj.GenerateResource.Cache

     文件       1212  2010-10-21 09:39  TreeListViewApp\TreeListViewApp\obj\TreeListViewApp.csproj.FileListAbsolute.txt

     文件        474  2010-10-20 17:12  TreeListViewApp\TreeListViewApp\Program.cs

     文件     543902  2010-10-20 17:18  TreeListViewApp\TreeListViewApp\Src.rar

     文件       1078  2010-10-21 09:18  TreeListViewApp\TreeListViewApp\images\CLSDFOLD.bmp

     文件       1078  2010-10-21 09:18  TreeListViewApp\TreeListViewApp\images\OPENFOLD.bmp

     文件       1078  2010-10-21 09:18  TreeListViewApp\TreeListViewApp\images\525FLOP1.bmp

     文件       1078  2010-10-21 09:18  TreeListViewApp\TreeListViewApp\images\NOTE12.bmp

     文件        560  2010-10-21 09:32  TreeListViewApp\TreeListViewApp\说明.txt

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

评论

共有 条评论