Saving and restoring a TreeView state in C# - c#

Consider a large TreeView; some nodes and subnodes are expanded others are collapsed. The user adds a child node to a node and the program saves everything back to the underlying XML file. Then the TreeView rebuilds. The problem is that only the root node is expanded; all other nodes are collapsed.
Has anybody ever seen code (I don't think there's anything built into WPF that does this) that saves the state of the TreeView (which nodes are expanded) and then is able to restore it to this state after a save?
Any ideas?
Edit
Well, that link didn't really help. I'm thinking of creating an array and storing the state of isExpanded and then reading it back after the load.

One has to manage the treeview's states directly and note when a node is expanded or collapsed. Then on load or refresh, open / close the nodes as needed.

Related

Infragistics Drag and Drop Tree Expand Multiple Nodes Simultaneously

I am using the following Infragistics component for viewing hierarchical data.
http://www.igniteui.com/tree/drag-and-drop-single-tree
I could able to load data correct but the problem is wI cant expand multiple nodes simultaneously. I mean when I expand a node the other node collapsed expanding only the current node. Can some one please suggest if there is any configuration setting I am missing to accomplish this?
I want the nodes once expanded will remain expanded until user collapses it again.
Thanks,
Krishna Prasad
The option that controls that is singleBranchExpand. Set it to false to allow multiple nodes to be expanded at the same time. http://jsfiddle.net/ywtLL7ka/
$("#tree").igTree({
singleBranchExpand: false,
});

How to set threeview node checkbox to mix state i.e. if any of the child node is selected, Parent node should fill in to indicate that

I am working on a windows form application, where I connect to the database and get a list of projects and sub-projects. I am able to show this as a treeview with checkboxes, that later an user can select to do further operations.
My problem is that, I can't set the Parent node state when one of the child nodes is selected. Here, I want some indication, if any of the child nodes is selected the parent node should fill in to show that something has been selected below that parent node.
Okay, meanwhile, I found answer to my problem. Not really wise but thanks to this Simple Tri-State TreeView control. code link here.
I will definitely try to build my own custom version of this. For now, this works fine.

how to remove image from treeview after added

Using visual studios 2010 and c# i have a treeview and i added images to each of the nodes. In retrospect i now want to remove the images that are associated with the children of the 3 main root nodes. How do i remove the images from the children of my 3 main root nodes but keep the images on the 3 root nodes?
I have tried opening the properties for the nodes and changed the ImageIndex and SelectedImageIndex to "none" for all of the children nodes and when i press ok, it still shows the default image for each child node.
Thanks
I'm not sure of it, but I believe that you can pass through every control inside the TreeView doing a foreach in [TreeView].Controls... In there you can search for [control].GetType() == typeof([type_of_the_image]), and do some logic to get just the main ones.
Besides that, you can remove by jQuery, doing something close to what I said above. If these ideas are something that interests you, I can help with the development.

Better than TreeView

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.

get the expanding node in a treeview

I have a treeview control that functions like a folder browser.
Because loading the entire folder structer from disk is taking a lot of time i'm trying to load only one level at a time.
So i have a function that adds nodes for all the folders in the current node.
I thought that the best method would be to run it on the BeforeExpand event of the treeview.
UpdateTreeView(TreeView.SelectedNode);
is not working because clicking the + sign to expand is not selecting the node also.
So how to find the node that is expanding.
The BeforeExpand event should work. It has a TreeViewCancelEventArgs which contains a Node property. It is essentially the node being expanded.

Categories

Resources