[Gambas-user] Newb needs help, Could I have an example of treefile save?

jbskaggs jbskaggs at ...1871...
Sat Mar 22 05:12:55 CET 2008


Ok this is new to me.  SO I will go and study class and collection and wrap
my mind around your lesson. 
Thank you.
JB SKaggs

Stephen Bungay-2 wrote:
> 
>    When last I looked, TreeView.Parent does not store the parent key of 
> the current node, but rather points you to the parent container for the 
> treeview control. As such TreeView.Parent is, for the purpose of storing 
> the tree structure, fairly useless.
>    You can use a collection and a class to store the tree structure. If 
> the tree itself can not give you the salient details you need to persist 
> it's structure to a table or text file, then it falls on you to create 
> the mechanism to do the job.
>    A class with three fields (lets call it ClassTree) can store what you 
> need.
> 
> Key
> ParentKey
> NodeText
> 
>    When you add a node to the tree you already know
> 1. What key you added or is to be added
> 2. What node text is going to be used
> 3. What the parent key is for the node being added
> 
> The time to capture this information is when you add a new node. You can 
> do something like this...
> 
> TreeClass = new ClassTree
> With TreeClass
>       .Key = KeyBeingAdded
>       .ParentKey = ParentKey
>       .NodeText = TextString
> end with
> 
> TreeCollection.Add TreeClass
> 
>    When it comes time to persist the tree to a file you simply walk the 
> TreeCollection by using a for-next loop. Your code might look something 
> like this...
> 
> open "myfile" as #1
> For X = 1 to TreeCollection.COunt
>      With TreeCollection
>           WRITE #1 .Key, .ParentKey, .NodeText
>      End With
> Next
> close #1
> 
>    Of course you can store the name of an image file (don't forget the 
> path to the file) as well. Just add the ImageName to the class, so your 
> class would look like this;
> 
> Key
> ParentKey
> NodeText
> ImageName
> 
> 
>    and adding it to the collection then looks something like this;
> 
> TreeClass = new ClassTree
> With TreeClass
>       .Key = KeyBeingAdded
>       .ParentKey = ParentKey
>       .NodeText = TextString
>       .ImageName = ImageName
> end with
> 
> TreeCollection.Add TreeClass
> 
>    Hope this helps.
> 
> Steve.
> 
> jbskaggs wrote:
>> As yall know I am just beginning programming, and In my program I am at
>> the
>> point of where I need to save my treeview.  But I am getting confused by
>> the
>> save commands.  
>> 
>> Could you show me an example of how exactly to open and save file that
>> would
>> record each treeview.item's characteristics:
>> 
>> ie  this is what I am thinking but it's not working and 
>> 
>>   open "myfile" as #1
>> 
>>   treecount = TreeView2.Count
>> 
>>   REPEAT 
>>     WRITE #1 TreeView2.Item.Key, TreeView2.Item.Image,
>> TreeView2.Item.Text,
>> TreeView2.Parent
>>     treeview2.MoveNext
>>     savecount+=1
>>   UNTIL savecount = treecount
>> 
>> so could somebody give the code to do this?
>> 
>> Thanks
>> 
>> JB SKaggs
> 
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> 

-- 
View this message in context: http://www.nabble.com/Newb-needs-help%2C-Could-I-have-an-example-of-treefile-save--tp16213218p16215561.html
Sent from the gambas-user mailing list archive at Nabble.com.





More information about the User mailing list