Asynchronous treeview node updating wpf wujaszek wania online dating
Perhaps you'll be my muse to do things the correct way.
I am populating a treeview using a recursive function as shown below.
However, the changes to the node only appear if I expand or contract a parent node, or add /delete a node, etc.
What is the best way to achieve a dynamic update without user intevention or reloading the tree?
But, i am choosing this as answer because its almost a one-liner code solution for my current situation. The following is a sample for an hierarchy which spans 3 levels: CS: The previous posts are completely right about the design with data binding.
Additionally, if you want to solve the issue to fill the tree asynchronously, you have to do this in another thread/task.
Keep in mind NET controls are very clumsy when dealing with large amount of items, so adding this 500,000 nodes will still be slow but atleast they were all generated on a different thread.
Object List View which comes with a Tree View too is a great library when dealing with large amounts of items; its fast, supports virtual mode and supports a lot of customization.
I display a "Loading.." message after the expand and remove it after the nodes are loaded. Now I want to change the loading message to "Loading..n/n".
I think the ui redraw is event driven for most MS packaged controls.
But @High Core is right, if you want to avoid code debt, abstract your complicated COM objects and their data behind a data source that you can plug into a XAML defined control. I know , the current code i have is not a better solution and it could be optimised with xaml and databinding. And there still needs to be a better implementation using a Data Template Selector if you want multiple levels.
Now for reporting back to the UI while a bg worker is on-going you should use Progress Changed event, this is thrown on the UI thread so you can update a Progress Bar or any needed control without the need of Invoke.
I leave you with this simple example I just made, 500,000 nodes in less than 1ms.
I have a method that executes on a different thread that applies the necassary changes to the treeview, i.e.