Sorry for making you confused. Let me elaborate it again.. This is our real scenario... We are using WPF and Data-binding. We are using ListCollectionView to bind the control (e.g. Datagrid, TreeView or etc) ... The reason why we are using ListCollectionView is that it supports sorting, filtering and etc... So, our code will be like that. Note: We are using MVVM pattern in our project so we dont want to write the code in code-behind. We wrote the most of code in ViewModel and bind that ViewModel with View.. ===== Class ===== class Person() : INotification { private int _id; private string _Name; private List myPets = new List; public int ID{ /// } public string Name{ /// } public List MyPets{ // } //impelementation for INotification. } then.. I bind it with TreeView. =========== View - XAML =========== Souce="Pet" // child class ... /> .... Pet.Name /> ItemSouce={... personListViewCollection } //personListViewCollection is the object from code below ... /> =========== ViewModel =========== ListViewCollection personListViewCollection ; void Constructor(){ populateData(); } void populateData(){ List persons = new List(); Person p1 = new Person(); p1.ID =1; .. List pets = new List(); pets.Add(new Pet(){ ...... } ); pets.Add(new Pet(){ ...... } ); p1.MyPets.AddRange(pets); person.Add(p1); /// add p2 p3 p4 ///note: // Let's say personListViewCollection.GetHashCode() == 1000100 personListViewCollection = new ListViewCollection(persons); } So, those data will be displayed on TreeView.. then, I wanna re-populatethe data. void reload(){ List newPersons = new List(); Person newP1 = new Person(); newP1.ID =1; .. List newPets = new List(); newPets.Add(new Pet(){ ...... } ); newPets.Add(new Pet(){ ...... } ); newP1.MyPets.AddRange(newPets); newPersons.Add(newP1); ///HERE is the problem. I dont want the hashcode of personListViewCollection to change. personListViewCollection = new ListViewCollection(newPersons); //Problem.. } then, I want to refresh the treeview and display the new data... Any Idea?
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)