This is a migrated thread and some comments may be shown as answers.

How to merge / combine 2 TreeListView into one?

1 Answer 31 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 27 Aug 2010, 10:11 AM

I have a TreeListView in my application and it has a timer that refresh the TreeListView each 30 seconds obtaining the new ItemSource from a web service. If I asign the new data for the TreeListView to the ItemSource every 30 sec. the full tree and the rowdetails collapse, so  to avoid that problem I have implemented the INotifyPropertyChanged interface, so if I make any change in the original structure the TreeListView show them without collapsing nodes or rowdetails. So that's why I need to merge the old TreeListView and the new TreeListView into the old one, adding or removing nodes in the original TreelistView. My tree structure is:

public class Tree : INotifyPropertyChanged
{
    private List<Object> data;
    private ObservableCollection<Tree> childnodes;

   public Tree(List<Object> list)
   { 
        info = list; 
        Nodes = new ObservableCollection<Tree>();
  }

public List<Object> info
{
   get { return data; }
   set
   {
      data = value;
      NotifyPropertyChanged( this, "info");
   }
}


public ObservableCollection<Tree> Nodes
{
    get { return childnodes; }
    set {
        childnodes= value;
        NotifyPropertyChanged( this, "Nodes");
    }
}


public event PropertyChangedEventHandler PropertyChanged;

public void NotifyPropertyChanged(object sender, string propertyName)
{
    if (this.PropertyChanged != null)
    {
         PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
   }

 }
}



And in the codeBehind:

....
if (radTreeListView.ItemsSource == null) //The first time
{
    original_tree = TreeService.GetTreeData(workflows);     //Returns an ObservableCollection<Tree>
   radTreeListView.ItemsSource = original_tree;
}
else      //Merge the new treeListView into the original (second and succesive times)
{
    new_tree = TreeService.GetTreeData(workflows);  //Returns the new ObservableCollection<Tree>
    MergeTrees (original_tree, new_tree);
}

....




Any idea to implement the MergeTrees function?

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Ivan
Top achievements
Rank 1
answered on 30 Aug 2010, 08:38 AM
Finally I have solved the problem with a recursive function that iterate between the 2 treelistviews, comparing element by element. 
Tags
TreeListView
Asked by
Ivan
Top achievements
Rank 1
Answers by
Ivan
Top achievements
Rank 1
Share this question
or