• 大小: 65KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-04-05
  • 语言: C#
  • 标签: C#  

资源简介

C#中实现一个TreeGridView(树形表格)示例代码C#中实现一个TreeGridView(树形表格)示例代码

资源截图

代码片段和文件信息

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

namespace TreeGridViewTestOnly
{
    public partial class Form1 : Form
    {
        public List personList = new List();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            //首先生成数据
            this.GenerateData();
            //然后生成列
            this.GenerateClo();

        }
        /// 
        /// 生成数据
        /// 

        private void GenerateData() {
            for (int i = 0; i < 100; i++)
            {
                Person p1 = new Person() { Id = i Password = “密码“ + i Level = 1 };
                for (int j = 0; j < 10; j++)
                {
                    Person p2 = new Person() { Id = j Password = “密码“ + j Level = 2 };
                    for (int k = 0; k < 10; k++)
                    {
                        Person p3 = new Person() { Id = k Password = “密码“ + k Level = 3 };
                        if (p2.ChildList == null)
                        {
                            p2.ChildList = new List();
                        }
                        p2.ChildList.Add(p3);
                    }
                    if (p1.ChildList == null)
                    {
                        p1.ChildList = new List();
                    }
                    p1.ChildList.Add(p2);
                }
                personList.Add(p1);
            }
        }

        /// 
        /// 生成列
        /// 

        private void GenerateClo()
        {
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.AllowUserToOrderColumns = false;
            this.dataGridView1.AllowUserToResizeRows = false;
            this.dataGridView1.AllowUserToResizeColumns = false;

            #region 影响性能

            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            this.dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            this.dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;

            #endregion

            this.dataGridView1.CellBorderstyle = DataGridViewCellBorderstyle.None;
            //this.dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
            this.dataGridView1.RowHeadersVisible = false;
            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-08-22 10:42  TreeGridViewTestOnly\
     目录           0  2019-08-22 13:32  TreeGridViewTestOnly\TreeGridViewTestOnly\
     文件         187  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\App.config
     文件        3740  2019-08-22 13:32  TreeGridViewTestOnly\TreeGridViewTestOnly\Form1.Designer.cs
     文件        8955  2019-08-22 13:32  TreeGridViewTestOnly\TreeGridViewTestOnly\Form1.cs
     文件        6181  2019-08-22 13:32  TreeGridViewTestOnly\TreeGridViewTestOnly\Form1.resx
     文件        1016  2019-08-22 10:43  TreeGridViewTestOnly\TreeGridViewTestOnly\Person.cs
     文件         532  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\Program.cs
     目录           0  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\Properties\
     文件        1364  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\Properties\AssemblyInfo.cs
     文件        2892  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\Properties\Resources.Designer.cs
     文件        5612  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\Properties\Resources.resx
     文件        1107  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\Properties\Settings.Designer.cs
     文件         249  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\Properties\Settings.settings
     文件        3857  2019-08-22 10:53  TreeGridViewTestOnly\TreeGridViewTestOnly\TreeGridViewTestOnly.csproj
     目录           0  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\bin\
     目录           0  2019-08-22 10:53  TreeGridViewTestOnly\TreeGridViewTestOnly\bin\Debug\
     文件       14336  2019-08-22 13:32  TreeGridViewTestOnly\TreeGridViewTestOnly\bin\Debug\TreeGridViewTestOnly.exe
     文件         187  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\bin\Debug\TreeGridViewTestOnly.exe.config
     文件       36352  2019-08-22 13:32  TreeGridViewTestOnly\TreeGridViewTestOnly\bin\Debug\TreeGridViewTestOnly.pdb
     文件       24224  2019-08-22 13:37  TreeGridViewTestOnly\TreeGridViewTestOnly\bin\Debug\TreeGridViewTestOnly.vshost.exe
     文件         187  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\bin\Debug\TreeGridViewTestOnly.vshost.exe.config
     文件         490  2012-06-06 02:06  TreeGridViewTestOnly\TreeGridViewTestOnly\bin\Debug\TreeGridViewTestOnly.vshost.exe.manifest
     目录           0  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\obj\
     目录           0  2019-08-22 13:32  TreeGridViewTestOnly\TreeGridViewTestOnly\obj\Debug\
     文件        1453  2019-08-22 13:30  TreeGridViewTestOnly\TreeGridViewTestOnly\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7047  2019-08-22 10:43  TreeGridViewTestOnly\TreeGridViewTestOnly\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2019-08-22 13:38  TreeGridViewTestOnly\TreeGridViewTestOnly\obj\Debug\TempPE\
     文件           0  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2019-08-22 10:42  TreeGridViewTestOnly\TreeGridViewTestOnly\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
............此处省略9个文件信息

评论

共有 条评论