TreeView和DataGridView.创建一个多级树 [英] TreeView and DataGridView. Creating a multilevel tree

查看:68
本文介绍了TreeView和DataGridView.创建一个多级树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一天中的好时光.请学习C#一周,有一点知识,请帮助我.
我需要借助在DataGridView中显示的组件来创建多级树.Dannye寻找了许多方法来组织它,并发现了一个相当简单直观的方法.填完字典后.节点是有组织的,因此用户无法理解该信息,因此称为混乱".我想组织另一个两级节点,如果我枚举它们将被称为表的列,并且它们保持字段值不变.
根=> ColumnName =>字段值,其中=>节点.
不幸的是,这是主要问题.
不要告诉我该怎么做?还是有一种更简单的方法来填充TreeView,从而避免使用字典,从而在其他节点上进行组织?
对不起,我的英语.

Good time of day. Learn C # for a week, a little knowledge, please, help me.
I need to create a multi-level tree with the help of the component are displayed in the DataGridView .Dannye looked for many ways to organize this and found a fairly simple and intuitive to me. After filling in the dictionary. Organized nodes on a level, so the information is not understandable to the user, so to say "mess." I would like to organize another two-level nodes, if I enumerate them that would be called as a column of the table, and they kept to the field value.
Root => ColumnName => Field Value , where => Nodes.
Unfortunately this is the main problem.
Do not tell me how to do this? Or is there an easier method of filling the TreeView, avoiding the dictionary, hence, on the other nodes are organized?
Sorry for my english.

namespace Tree
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Size = new Size(1600, 500);
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'releaseBDDataSet.Zakazchiki' table. You can move, or remove it, as needed.
            this.zakazchikiTableAdapter.Fill(this.releaseBDDataSet.Zakazchiki);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            treeView1.Nodes.Clear();
 
            Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();
           
 
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                string FullName = (string)row.Cells[3].Value;
                string Name = (string)row.Cells[4].Value;
                string INNKPP = (string)row.Cells[5].Value;
                string OGRN = (string)row.Cells[6].Value;
                string UAdres = (string)row.Cells[7].Value;
                string MAdres = (string)row.Cells[8].Value;
                string Req = (string)row.Cells[9].Value;
                string Number = (string)row.Cells[10].Value;
                string OKVED = (string)row.Cells[11].Value;
                string OKPO = (string)row.Cells[12].Value;
                string OKFSOKOPF = (string)row.Cells[13].Value;
                string GDer = (string)row.Cells[14].Value;
                string GBug = (string)row.Cells[15].Value;
                string RNPF = (string)row.Cells[16].Value;
                string RNFCC = (string)row.Cells[17].Value;
                string RNRFOMC = (string)row.Cells[18].Value;
                string OKATO = (string)row.Cells[19].Value;
                if (FullName == null)
                    continue;
                if (dict.ContainsKey(FullName))
                {
                    dict[FullName].Add(Name);              
                    dict[FullName].Add(INNKPP);                  
                    dict[FullName].Add(OGRN);
                    dict[FullName].Add(UAdres);
                    dict[FullName].Add(MAdres);
                    dict[FullName].Add(Req);
                    dict[FullName].Add(Number);
                    dict[FullName].Add(OKVED);
                    dict[FullName].Add(OKPO);
                    dict[FullName].Add(OKFSOKOPF);
                    dict[FullName].Add(GDer);
                    dict[FullName].Add(GBug);
                    dict[FullName].Add(RNPF);
                    dict[FullName].Add(RNFCC);
                    dict[FullName].Add(RNRFOMC);
                    dict[FullName].Add(OKATO);
                                                   }                
               else
                {
                    dict.Add(FullName, new List<string>());
                    dict[FullName].Add(Name);
                    dict[FullName].Add(INNKPP); 
                    dict[FullName].Add(OGRN);
                    dict[FullName].Add(UAdres);
                    dict[FullName].Add(MAdres);
                    dict[FullName].Add(Req);
                    dict[FullName].Add(Number);
                    dict[FullName].Add(OKVED);
                    dict[FullName].Add(OKPO);
                    dict[FullName].Add(OKFSOKOPF);
                    dict[FullName].Add(GDer);
                    dict[FullName].Add(GBug);
                    dict[FullName].Add(RNPF);
                    dict[FullName].Add(RNFCC);
                    dict[FullName].Add(RNRFOMC);
                    dict[FullName].Add(OKATO);                
                   
                }                     
            }
            foreach (var kvp in dict)
            {
                TreeNode parent = new TreeNode(kvp.Key);
                foreach (string Child in kvp.Value)
                {
                    parent.Nodes.Add(Child);
                }
                treeView1.Nodes.Add(parent);
            }  
        }              
    }
}

推荐答案


我想您正在寻找多层网格,这可能对您有所帮助.

http://demos.telerik.com/aspnet-ajax/grid/examples/编程/webmail/defaultcs.aspx [ ^ ]

检查示例,他们在框架中得到了不同的多层网格解决方案.希望这会有所帮助.
Hi,
I guess you are looking for multi level grids, this may helpful for you.

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/webmail/defaultcs.aspx[^]

Check the examples, they got different multilevel grid solutions packed in their framework. Hope this helps.


这篇关于TreeView和DataGridView.创建一个多级树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆