locked
How to store a TreeView state and restore it back RRS feed

  • Question

  •  

     hi everyone,

    My code looks like this

    dataentryTreeView.Dispose() ;  // disposes off the old tree

    InitializedataentryTreeView();  // again rebuilds the tree with the updated information

    return true;

    Everytime i add,update or delete a node from my treeview it disposes the old tree view and rebuilds a new tree with updated information but the problem i am loosing the previous state of the tree view so it's becoming hard to navigate again and see where we have added the node.

    could anyone help me in saving the state of the treeview before i dispose off the old treeview and restore the state back again after rebuilding the new treeview

    thanks,

    prawin josh

     

     

     

    Wednesday, April 19, 2006 5:58 AM

Answers

  • Last hit before i will write a state storing example, why don't you rebuild your logic? Because your logic isn't logic, you should never throw away things you can easy re-use!

    In my humble opinion this is a bad design and you should modify it! If you need any help with it, please let me know. I would rather help you with a new design then with help you in a evil direction.
    Friday, April 21, 2006 7:23 AM

All replies

  • Why do you Dispose it if you want to keep the state? And what do you exactly mean with the state?
    Wednesday, April 19, 2006 7:26 AM
  •  

    i am disposing off the tree and rebuilding it because my intention is to refresh the tree everytime i do some operation on it but for example if am adding a node to the treeview at level 1 and if i rebuild without diposing the old tree it is adding as a separate treenode so i am disposing off the old treeview and rebuilding a new one.

    now before i dispose the old tree i want to save the exact expanded state of the tree view and restore the expanded state after rebuilding the tree so that it would exactly be in the previous expanded state showing where we added a node or so....

    regards,

    prawin josh 

    Wednesday, April 19, 2006 8:48 AM
  • This is posible, but i still don't see the reason. You rebuild it, why don't you just add or remove some nodes and update the outdate notes.

    You can change the TreeNode.Text property instead of removing everything and rebuild it again. When you do this the expane state will be the same because you only change the Text property.
    Wednesday, April 19, 2006 8:53 AM
  • yes but i am building dyanamically from a datatable so eveytime i make some changes it has to reflect in my database and rebuild the tree from the database table so i am doing like that

    changing the text property wont reflect in backend(database) anyway your solution works fine for edit but for add and delete nodes we have definitely reload the tree for that i want to save the previous expanded state and restore it back after rebuilding the tree

    thanks,

    prawin josh

    Wednesday, April 19, 2006 9:09 AM
  • You don't have to rebuild the TreeView if you add or delete nodes. Do you get exception when you do that?
    Wednesday, April 19, 2006 12:06 PM
  • Everytime i  add a node to the tree, i add first that node information to the database table and then retrieve that data from table and rebuild the tree so for my logic it is mandatory to rebuild the tree as it's added to data table first and then to the tree.

    thanks,help would be appreciated

    regards

    prawin josh

    Friday, April 21, 2006 5:39 AM
  • Last hit before i will write a state storing example, why don't you rebuild your logic? Because your logic isn't logic, you should never throw away things you can easy re-use!

    In my humble opinion this is a bad design and you should modify it! If you need any help with it, please let me know. I would rather help you with a new design then with help you in a evil direction.
    Friday, April 21, 2006 7:23 AM