Dynamically Populate a TreeView using 2 dimensional list or array's in C# -


i trying populate pre-existing treeview, items 2 dimensional source such list> or array[,].

for example imagine had list follows:

sarah, john, jill, bill

sarah, joe, jill

matt, micheal, sue, george

matt, micheal, sue, george, sam

in example if name exists on left persons parent, , right represents child.

i started writing following code got stuck:

 private treenode parentchild(treenode node, string parent, string child)     {         if (!node.nodes.containskey(parent))         {             treenode p = new treenode(parent);              p.name = parent;              node.nodes.add(p);         }         if (!node.nodes[parent].nodes.containskey(child))         {             treenode c = new treenode(child);             c.name = child;             node.nodes[parent].nodes.add(child);         }    private treeview addnode(list<list<string>> keys, treeview tree, treeview tree1)     {           for(int i=0; i<keys.count;i++)         {             treenode top= new treenode();             if(tree.nodes.containskey(keys[i][0]))                  top= tree.nodes[keys[i][0]];             for( int j = 0; j<keys.count-1; j++)             {                  treenode = parentchild(top,keys[i][j],keys[i][j+1]);             }             tree.nodes.add(top);         }       } 

example of nested list: public void example() {

       list<list<string>> example = new list<list<string>>();         list<string> tmp = new list<string>();         tmp.add("sarah");         tmp.add("john");         tmp.add("jill");         tmp.add("bill");         example.add(tmp);         list<string> tmp2 = new list<string>();         tmp2.add("sarah");         tmp2.add("joe");         tmp2.add("jill");         example.add(tmp2);         list<string> tmp3 = new list<string>();         tmp3.add("matt");         tmp3.add("micheal");         tmp3.add("sue");         tmp3.add("george");         example.add(tmp3);         list<string> tmp4 = new list<string>();         tmp3.add("matt");         tmp3.add("micheal");         tmp3.add("sue");         tmp3.add("george");         tmp4.add("sam");         example.add(tmp4);      } 

any appreciated.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -