c# - WPF returning a List to the class -


new wpf , c# vb web forms, sorry poorly structured question add needed improve. trying implement example adding database calls mysql populate on-demand tree view control. here link sample code...

sample code

got db connection working , data populating dataset. iterate place in list. can not seem figure out issue passing list class populate control...

public class level1 {     public level1(string level1name)     {         this.level1name = level1name;     }      public string level1name { get; private set; }      readonly list<level2> _level2s = new list<level2>();     public list<level2> level2s     {         { return _level2s; }     } } 

i have database class queries db , parses data....

list<string> level1s = new list<string>(); dataset ds = new dataset();  foreach (datatable table in ds.tables) {     foreach (datarow row in table.rows)     {         level1s.add((string)row["name"]);     } }   **update**: trying return list...  return new level1[]   {   foreach(datarow row in level1s)   {     // iterate here                  } }; 

my level1s list populated, drawing blank on returning values.

thanks,

update - including viewmodel code here well....

using businesslib;  namespace treeviewwithviewmodeltoc.loadondemand {     public class level1viewmodel : treeviewitemviewmodel     {         readonly level1 _level1;          public level1viewmodel(level1 level1)              : base(null, true)         {             _level1 = level1;         }          public string level1name         {             { return _level1.level1name; }         }          protected override void loadchildren()         {             foreach (level2 level2 in database.getlevel2s(_level1))                 base.children.add(new level2viewmodel(level2, this));         }     }  } 

try below,

list<level1> l1=new list<level1>();  foreach(var row in level1s)  {     level1 l=new level1();     // l.level1name = row.tostring(); here add items need     l1.add(l);   }  return l1.toarray(); 

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 -