I’m loading a TreeView from a list, and the user has a button to delete an item and it deletes it from the list no problem, but there is also a button to update the TreeView with the list after items have been deleted, I have no problem adding the new items to the TreeView but is there a way to clear all the items in the TreeView before I add new items, so I don’t have duplicates in the TreeView? I have tried looking on other spots on the internet for the answer but cant find it, I’ve tried simple things like:
treeView1.Items.Clear();
but it doesn’t work.
Sorry, I mentioned it on a comment, below that I’m pretty sure this line does in fact clear it, I am just not using it in the right place, thanks all for your answers.
First of all, Items and Clear should be capitalized in your example. Maybe that’s the only problem.
Second, if you are populating the tree by setting its ItemsSource, then you are not allowed to add and remove items from its Items collection by hand. Instead, you should make the source an ObservableCollection instead of a List. Then the treeview will automatically update itself to reflect changes in the source collection