Tuesday, June 14, 2011

WPF - TreeView list update

For updating a tree view (after removing elements) the tree view did not change - all elements still appeared on it.


Use an ObservableCollection for the tree view items:

ObservableCollection fileList = new ObservableCollection();

to add:

list.ItemsSource = fileList;

and remove items like this:

ObservableCollection auxList = new ObservableCollection();

foreach (string item in fileList)
if (!TheListview.SelectedItems.Contains(item))
fileList = auxList;
TheListview.ItemsSource = fileList;

I've tried items refresh, setting the collection to invalid but none worked.

No comments: