Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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);
            }  
        }              
    }
}
Posted
Comments
Sergey Alexandrovich Kryukov 8-Aug-12 14:58pm    
What is "multilevel tree"? Aren't they all "multilevel"? Perhaps, you are talking about "multi-level GridView"? Would be great to have...
--SA
sk1zZ 9-Aug-12 6:07am    
Sorry, if you put it is not clear. I was talking specifically about TreeView, perhaps you're right, they all are multilevel.
Sergey Alexandrovich Kryukov 9-Aug-12 13:11pm    
As I say: would be great to have. Unfortunately, I don't know such component. I knew such thing for Delphi, a virtual tree view with columns, but I had defects needed some work-around. It's quite possible to design and develop such component from scratch, but... it would be quite a big project.
--SA
Kenneth Haugland 8-Aug-12 17:04pm    
You seem to be looking for a Binary Tree
Sergey Alexandrovich Kryukov 9-Aug-12 13:07pm    
I don't think so. A concept of binary tree is a pure data structure, and this is UI.
--SA

1 solution

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.
 
Share this answer
 
Comments
sk1zZ 9-Aug-12 6:18am    
Hello, thanks for the help. The examples that you suggested, did not use Datagrivview, and on my form must exactly two elements are placed DataGridView and connected with him TreeView.
I created a root node and the child can not. How to create a child node to contain the value of the columns, and in them was the value of the fields is my question.
Sorry, if you put it is not clear.
Sergey Alexandrovich Kryukov 9-Aug-12 13:09pm    
As I understand it correctly, this is a two-level grid, but OP needs the multi-level, perhaps looking like a hybrid between a TreeView and a Grid.
--SA
sk1zZ 9-Aug-12 15:18pm    
Maybe I'll explain that? For Example :
That TreeView i want to do :
FullName ( Its a name one of my column in DataGridView)
|__Nubmer( This is also the name of my column in DataGridView )
| |__223355 ( This is value of the cell in column Number in DGW)
|____UAdres
| |__Street1
|______etc.
In my code, only the root nodes are creatred, and how to make a child to them, as I have shown in the example above, I do not know.
In my code, rather than, for example, the "Number" node stored field value in the column "Number",i.e "223355".
This is how it works now:
FullName
|__223355
|__Street1
Sergey Alexandrovich , do you happen to know Russian language? This would improve understanding.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900