Clearing a TreeView

BlitzPlus Forums/BlitzPlus Programming/Clearing a TreeView

What's the best way to clear out and rebuild a tree-view? I'm downloading the content for it from a website and the tree is built based on the content of the download.

I want the user to be able to click a button to refresh the treeview - but obviously I'll need to empty it first. How?

All help appreciated. :)

FreeTreeViewNode(TreeViewRoot( treeview ))
This will flush it nice and quick, but I haven't checked if it deletes the Nodes or leaves them as orphans.

Thanks for that - but when I try to refill the list after calling FreeTreeViewNode I get "invalid node" - presumably because as far as it's concerned, the tree is a dead gadget now?

If you want to refill the treeview, you'd need to assign another root node to it before you start adding new stuff.

Can you provide a sample piece of code for this?

I tried AddTreeViewNode "Some text",TreeViewRoot(tv_GameList) after calling FreeTreeViewNode, and it still complained.

It'd be much appreciated, thanks in advance!

Strange. I get the same thing here too. When i delete the treeview root node, assign a new one, then try and add a new node, i get the "invalid node" error. Is this a bug? Of course, I could be missing something obvious.

What you might have to do, Mikkyx, is free the treeview gadget entirely, then create a new one, add the new root node to that, then build your treeview from there. Or you could store a list of all the nodes in your treeview (excluding the root node), and free them all using those. But you'd have to be careful about freeing a parent node, then trying to free one of its child nodes. This would throw up an error, IIRC.