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)
{
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);
}
}
}
}