SOBKing
asked on
How To Save A TreeView To A File
my question is for C++Builder
i have a TreeView with multiple nodes.. each node has the .data property set to point to some structure with additional info about that node
now i need to know how to save that TTreeView to a file of some kind and then load it again...
and i need the .data to be saved as well so when im done loading it.. it will be there too!
please dont tell me to use the .SaveToFile property as that wont save the .data part (unless im doing something wrong)
just incase no one know what im talking about the .data thing i will give some code
here is the code i use to add an item to the tree
//The Structure
struct TreeLeaf {
char Name[40];
char Description[100];
char Pin[2];
char Light[8];
};
//The Add Code
TreeLeaf *data;
TTreeNode *node;
data = (TreeLeaf *)malloc(sizeof(TreeLeaf)) ;
strcpy(data->Pin, "00");
strcpy(data->Light, "00000000");
strcpy(data->Description, "New Item");
node = spSkinTreeView1->Items->Ad d(NULL,"Ne w Item");
node->Data = data;
node->Selected = true;
Current = node;
so as you can see each node has some additional data attached to it.. which is critical to be saved along with the tree..
i have a TreeView with multiple nodes.. each node has the .data property set to point to some structure with additional info about that node
now i need to know how to save that TTreeView to a file of some kind and then load it again...
and i need the .data to be saved as well so when im done loading it.. it will be there too!
please dont tell me to use the .SaveToFile property as that wont save the .data part (unless im doing something wrong)
just incase no one know what im talking about the .data thing i will give some code
here is the code i use to add an item to the tree
//The Structure
struct TreeLeaf {
char Name[40];
char Description[100];
char Pin[2];
char Light[8];
};
//The Add Code
TreeLeaf *data;
TTreeNode *node;
data = (TreeLeaf *)malloc(sizeof(TreeLeaf))
strcpy(data->Pin, "00");
strcpy(data->Light, "00000000");
strcpy(data->Description, "New Item");
node = spSkinTreeView1->Items->Ad
node->Data = data;
node->Selected = true;
Current = node;
so as you can see each node has some additional data attached to it.. which is critical to be saved along with the tree..
ASKER
ok thanks i will look into that!
one thing i was thinking of is..
1st.. just saving the tree with the .save to file...
then after thats saved.. run thru the tree.. and for each node write the .data to a file
then when opening it...
open the ree with the loadfromfile...
then after its loaded.. run thru the tree backwards and set the .data property from that file..
the only problem with that is i dont know how to traverse a complicated tree... i know how to do a birnar tree with recursion..
one thing i was thinking of is..
1st.. just saving the tree with the .save to file...
then after thats saved.. run thru the tree.. and for each node write the .data to a file
then when opening it...
open the ree with the loadfromfile...
then after its loaded.. run thru the tree backwards and set the .data property from that file..
the only problem with that is i dont know how to traverse a complicated tree... i know how to do a birnar tree with recursion..
If you traverse it root - left node - right node, save to file and restore in same manner then it will remain same.
For complex tree - if there is one root with 3 childs - process root, first child, second child, third child...
That is the way.
Bojidar Alexandrov
For complex tree - if there is one root with 3 childs - process root, first child, second child, third child...
That is the way.
Bojidar Alexandrov
ASKER
ya i understand the theory kinda.. thats what we doing in classes right now.. its the code i have no idea..
i dont understand enough about to do that...
if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points.. :)
oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out
thanks
i dont understand enough about to do that...
if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points.. :)
oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out
thanks
ASKER
ya i understand the theory kinda.. thats what we doing in classes right now.. its the code i have no idea..
i dont understand enough about to do that...
if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points.. :)
oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out
thanks
i dont understand enough about to do that...
if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points.. :)
oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out
thanks
ASKER
ya i understand the theory kinda.. thats what we doing in classes right now.. its the code i have no idea..
i dont understand enough about to do that...
if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points.. :)
oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out
thanks
i dont understand enough about to do that...
if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points.. :)
oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out
thanks
ASKER
ya i understand the theory kinda.. thats what we doing in classes right now.. its the code i have no idea..
i dont understand enough about to do that...
if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points.. :)
oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out
thanks
i dont understand enough about to do that...
if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points.. :)
oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out
thanks
please release the submit button :-))
i advice you to read the link i gave first
meikl ;-)
i advice you to read the link i gave first
meikl ;-)
ASKER
i thinkt he stuf in the other post is wayyyyy over my head...
lol i guess i pressed it one too many times hah
lol i guess i pressed it one too many times hah
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.experts-exchange.com/questions/10120892/saving-treeview-data-nodes-to-file.html
you may find there some solutions, how this could be done
meikl ;-)