Silverlight / WPF - Remove all treeview nodes in wpf

Asked By snehasis mishra on 19-Nov-12 01:30 AM
Hi,
 
I am working with wpf treeview.i have bound the treeview with it's data context property.but whenever i am trying to refresh the treeview by clearing all the nodes,it's not allowing.i have tryed treeview1.items.clear();.but it throws exception.Please suggest me how can i solve this problem.
 
Regards,
Snehasis
Robbe Morris replied to snehasis mishra on 19-Nov-12 09:24 AM
Is the data in an ObservableCollection and bound to the treeview?  If so, you should just be able to clear the collection itself.

Also, on a TreeView, each node has a .Nodes collection.  You have to recursively clear each node's children.  There is not a built in method on the TreeView that does this for you.