C# WPF ChildObservableCollection CRUD -


i create listbox(main) , listbox have datatemplate binding observablecollection.

also, listbox have many listbox(child), binding child observablecollection.


*observablecollection < list >

  -(int)id

  -(string)data

  -(class)a

  -observablecollection < list2 >

     -(int)list2_id

     -(string)sdata1

  -observablecollection < list3 >

     -(int)list3_id

     -(string)sdata2

  -observablecollection < list4 >

     -(int)list4_id

     -(string)sdata3

...


list2 nlst = new list2();

nlst.id = 1;

list.list2.add(nlst); //set child observablecollection.

the childobservable cannot set in case:

        public observablecollection<childclass> cc         {                         {                 return mainlist._cc;             }             set             {                 onpropertychanged();             } 

however updated to:

        public observablecollection<childclass> cc         {                         {                 return mainlist._cc;             }             set             {                 foreach (var tmp in value)                 {                     bool found = false;                     bool edit = false;                     foreach (var ct in mainlist._cc)                     {                         if(ct.id == tmp.id)                         {                             found = true;                             if (!object.referenceequals(tmp, ct))                             {                                 edit = true;                             }                         }                     }                     if (found)                     {                         if (edit)                         {                             //update                             ct.id = tmp.id;                             ct.status = tmp.status;                          ...                         }                     }                     else                     {                         if(tmp.status == -1)                         {                             mainlist._cc.remove(tmp);                         }                         else                         {                             mainlist._cc.add(tmp);                         }                     }                 }                  onpropertychanged();             } 

it can add,update,delete ..

but need 2 for-each checking , performance low...


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -