I'm binding a lot of data to a TreeView control as the data is a natural category hierarchy. The problem is that there is a lot of it. I have managed to remove a lot of the overhead by only binding those nodes which appear in the visible tree, but this still leaves a lot in the ViewState, et al.
Does anyone have a method or alternative control for improving this kind of performance issue, please?
I was thinking about trying to inherit the TreeView control and dump it's viewstate value into Sesssion and back - but it's quite a hack I don't really have time for, right now...
Yes ... you can use On-demand Loading or Lazy loading of Tree View Items
i.e.
1- Only show root level nodes as in the Window Explorer.
2- when user Clicks a node , than only fetch the child nodes and show.
in this way , you will see only those nodes which actually user requested.
and you can give a checbox , which say 'SHOW WHOLE TREE EXPANDED' obviously , it would take more time to show.
you can also implement Node search functionality but please remember tree is specilized form a graph so use proper grpah algorithm while finding a node like (BFS or DFS)
you can also cache the results of nodes but this should be only done in the case when your tree itself is not used for hierarchy updation.
apart from the solution of dynamically loading tree view on expand, try ViewStateCompression for viewstate enhancement, use Asp.net Caching for output caching or just cache the objects by dynamically adding objects to cache using generating keys like "tree_" & parent. Cache objects are shared between sessions, so it will even be more helpful.
Hope this will help.
Related
My problem is the following: I got a Tree which has an dynamic depth of categories (each category can have sub-categories as well as entries).
Now I added a HierarchicalDataTemplate for the categories to display correctly in the TreeView. But I get a lot of empty entries, which do not apply the Template (wrong type) but show up in the tree as 'corpse'.
How can I ban them from the generation process? Because it's an abstract tree, they are of the same base-class as the categories are. So they get into the tree, because the tree always searches the "Branches"-property which contains either categories, entries or both.
Any ideas? I didn't find any event of the TreeView which probably give me the opportunity to skip various entries during generation nor any option/property of the template to do so.
Detailed Description: I got a generic Tree class. This class has branches of type "A_TreeLeaf" (abstract). The Tree's generic type must inherit A_TreeLeaf of course. My data is structured in categories (CategoryTreeLeaf) and Data (DataTreeLeaf). Each leaf can have sub-leaves (branches), of course.
Now I load my data from a database and build the tree. Each category has X sub-categories. And each category also could contain some Data. This structure helps me a lot, because I got an clear hierarchic structure of categories and data. This way it should be visualized to the user. But I want to separate Data and Categories. The TreeView should show just the categories (by an HierarchicalDataTemplate) and the ListView just the Data (by an DataTemplate). The ListView works fine, but the Tree shows some "corpse"-entries which are the DataTreeLeaf-instances.
I want to filter the DataTreeLeafs on generation or just stop the TreeView displaying them. Is there any "non-hack" solution? I don't want to copy the tree and remove the Data-leaves unless it's really necessary... because this would cause a lot of overhead work to do for me and to manage either the code behind which uses the real tree or the visualization with the fake-tree (because I need to bridge it somehow that it's updated automatically when one of both changes).
You have a unique problem... you have some data items in your hierarchical data that you don't want to display, but for some reason can't remove. If that sums up your problem, then you're doing something wrong.
In WPF, you shouldn't need to hide data items from the UI, instead you simply don't put them into the collection in the first place. It sounds like your process of filling your hierarchical data is flawed and you'd be better off fixing that at the source than trying to deal with the problems that it causes in the UI.
If you can't fix the actual process for whatever reason, then your next best option is to iterate through the data before you display it and simply remove any data elements that shouldn't be there. When using WPF, it is always best to provide your UI with data that fits the purpose.
However, if for whatever reason you can't even do that, then your last option is to simply define an additional DataTemplate for your abstract base class and just leave it empty:
<DataTemplate DataType="{x:Type YourDataTypesPrefix:YourBaseClass}">
</DataTemplate>
Of course, you'd have to define DataTemplates for each sub type, or they'd also be rendered empty.
I’m trying to display images in a ASP.NET (web) TreeView control. Basically in the DB there is 1, 2 and/or 3 ticked and everything that is checked should cause an appropriate image(s) to appear next to that node on the tree. This all works except for then there is postback
I’ve used this [http://www.codeproject.com/Articles/14031/Displaying-Multiple-Images-In-The-ASP-NET-TreeView] and it works ok, except for when a postback occurs.
In addition to the +- symbols I also use the onselectednodechanged method, this causes the postbacks (this is ok as other things are happening on the page at the same time). But the postback looses the fact that it should display the images and they disappear.
I can only assume that the images are not saved in the viewstate as when the tree is rendered it opens to the correct point but ignores the images.
Is there a better way to have images displayed in a tree view? Or a simple way of telling the view state to remember the images
------------------ Extra info ---------------
I've just watched what happens to the nodes / child nodes during the postback. they revert to there default types.
When I create them they are created a ImageTreeViewNode which is inherited from the TreeNode.
After the post back the nodes are all TreeNode rather then ImageTreeViewNode. Is there a way to stop them reverting and loosing the extra info?
Ended up solving this by extending the TreeView class and the new 'ImageTreeView' class for my treeview control.
I changed the createNode method to use the new ImageTreeNode class (the extended TreeNode class)
Not sue if it's a good or bad solution, but it seams to work.
In my application as soon as an object is dropped on canvas I stored it in a tree. Now, I'm trying to write a method to delete an object which is fine but I also need to delete that specific object from the tree. Each object has a unique id so this way I can find it in tree and remove it from tree while being deleted from the canvas.
In order to find a node in tree I have planned to store ID in each node (item.Tag), however, I'm facing two problems:
How can I access to details of a node from a different class? myTreeObj.Items.Tag doesn't work properly.
When I loop in tree myTreeObj.Items.Count shows more items that what I see.
Any comments will be appreciated.
Thanks.
In WPF, TreeViews are actually what they say they are: a view of a data structure. In WinForms, you had to crawl up and down the nodes of a TreeView and add them or remove them manually. In WPF, the proper approach is to add or remove items from the actual data hierarchy (to which the TreeView is binding) and use PropertyChanged or CollectionChanged notifications to tell the TreeView to update itself automatically.
What you are trying to do may be possible, but it is going to be an uphill fight all the way, and things will not work as expected. WPF REALLY wants you to use databinding, and any other approach is going to give you headaches.
This article may be a helpful place to start understanding how to work with the WPF TreeView:
http://joshsmithonwpf.wordpress.com/2008/05/24/the-wpf-treeview-is-a-view-of-a-tree/
EDIT:
The author's original article is actually more helpful:
http://www.codeproject.com/Articles/26288/Simplifying-the-WPF-TreeView-by-Using-the-ViewMode
I'm using WPF TreeView bound to my classes though MVVM to display a large array of multilevel data. Because of this, when I expand TreeNode, it takes some time and a lot of memory.
I think, that the memory requirement comes from TreeView scouting out nodes down the line, not just the first generation of the children, forcing those nodes to load data.
Is there any way to limit this "scouting" behavior to only the first generation of child nodes?
WPF generates TreeViewItem(s) only when they are displayed, i.e. no item is generated until its Parent expanded. So, I think the problem is not a "scouting".
Anyway, you may try to implement dynamic loading in your ViewModel by adding synchronization with TreeViewItem.IsExpanded using TwoWay Binding. Take a look at this. You may use the same solution for IsExpanded property. Don't forget to add fake item to tell TreeViewItem that it is expandable.
Check if TreeView is using VirtualizingStackPanel. I believe that it is used by default in .NET 4.0, but you must set it explicitly in previous .NET versions.
For more information, see How to: Improve the Performance of a TreeView.
I'm new to the "Telerik"-controls and I have a few questions! First of all, I'll give you a small resume of what we want to achieve and how I did it for now.
The customers has several clients who come to present themselves and they need to fill in their qualities (language skills, education, ....). Therefor we've created some templates (that already contains some crucial data). The templates can be hierarchical => Language Skill Dutch has two children : "Writing", "Speaking". They see that in an Hiearchical treeview (for now).
If they select the item in that tree, they automatically create a quality (with the templateid, contactid, etc...) for that type of template. Each time they call the treeview for that contact, the template who has a quality will be checked! And if they click on "Edit", they'll be able chaging some info of the quality.
That's in short what it does now and what's behind it. Now, they wanted a nicer looking method without having popups and such (everything in one screen). Then i found the "RadTreeList" of telerik. But for now I'm having the following problems :
The root of the tree can't be selected (best would be that the checkbox is hidden) => how do I achieve this?
Is it possible to hide the "EDIT"-button on the root? The root should never be selected on his own (no qualities for root elements).
So the big question, how can I take an item while looping through the whole treelist collection and say that I don't want to show checkbox and such?
With my treeview I iterated through all the nodes and then I did the needed modifications. But 1 => It was slow, 2 => It looked that nice, 3 => It didn't match they look of the CRM 2011.
What i've already achieved is showing everything hiearchical and select the "Node-Templates" (if I can call it so) that contains Qualities.
Hopefully you have enough info... If there are better alternatives, I'm open for everything, but it's kind off urgent, cause we'll have a demo-session soon :)
Info => It has to be in ASP.NET (C#)
It is true that you cannot select the 'root' of the treelist, but you can place an item in the first column to add new items at root level as illustrated here: http://demos.telerik.com/aspnet-ajax/treelist/examples/dataediting/net35automaticdataediting/defaultcs.aspx.
To hide the edit button for root level items, listen to the ItemCreated event, locate the edit button in the root items only and set its Visible property to false. This should work for checkboxes or other server controls inside the treelist rows and you do not have to perform explicit loops through the items later on.