database - Create Treeview depending on DataGridView in C# -


i data tow database, db1,db2, want create treeview data in resulting datagridview; in datagrid view there are: id, name, director,the first record prim director, mean has not director(he owner), each record has no other record or has more records(child), , each child has grandchild , on, scenario in page: i want create treeview (parent , child , grandchild , on), depending on xml file when used snippet after :

void settree()         {             {             foreach(datagridviewrow dt in datagridview1.rows)             {            var per = this.datagridview1.rows.cast<datagridviewrow>().select(n => new person                 {                     name = dt.cells[0].value.tostring(),                     sex = dt.cells[1].value.tostring(),                     status = dt.cells[2].value.tostring(),                     child = dt.cells[3].value.tostring(),                     id = dt.cells[4].value.tostring(),                     father = dt.cells[5].value.tostring()                 }).tolist();                var roottreenode = gettree(per, "").first();.........(1)                treeview1.nodes.add(roottreenode);             }           }         }                private treenode[] gettree(list<person> per, string parent)         {             return per.where(p => p.father == parent).select(p =>             {                 var node = new treenode(p.name);                 node.tag = p.id;                 node.nodes.addrange(gettree(per, p.id));                 return node;             }).toarray();         } 

now, when use code, error @ mark(1),it say:additional information: sequence contains no elements.

thank

after several readings in internet , attempts solve small problem, successed finally. solution:

{ ............. treenode tn = new treenode(this.datagridview2.rows[0].cells[0].value.tostring());//text tn.tag = this.datagridview2.rows[0].cells[4].value.tostring();// id tn.name = this.datagridview2.rows[0].cells[5].value.tostring();//directorid                 treeview1.nodes.add(tn);                 settree(tn);             }             public void settree(treenode ns)         {             foreach (datagridviewrow dr in datagridview2.rows)             {                 if (dr.cells[5].value.tostring() == ns.tag.tostring())                 {                     treenode tsn = new treenode(dr.cells[0].value.tostring());                     tsn.tag = dr.cells[4].value.tostring();                     tsn.name = dr.cells[5].value.tostring();                     ns.nodes.add(tsn);                     settree(tsn);                 }             }         } 

i happy if benefit code.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -