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

Benoit Minisini gambas at ...1...
Sat Mar 22 21:39:00 CET 2008


On samedi 22 mars 2008, 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

As treeview is a recursive structure, you must replace 
the "treeview2.MoveNext" line by the following algorithm:

' Moves to the first item
treeview2.MoveFirst()

WHILE treeview2.Available

  ' Do your job there...

  ' Moves to first child
  treeview2.MoveChild()
  ' No first child ? Go to the next sibling
  IF NOT treeview2.Available THEN 
    treeview2.MoveBack() ' Returns to the current item
    treeview2.MoveNext()
  ENDIF
  ' I am the last child of my parent ?
  IF NOT treeview2.Available THEN
    treeview2.MoveBack() ' Returns to the current item
    DO
      ' Go to the parent
      treeview2.MoveParent()
      ' No more parent ? Stop
      IF NOT treeview2.Available THEN BREAK
      ' And maybe its next sibling
      treeview2.MoveNext()
      ' If there is a next sibling, stop
      IF treeview2.Available THEN BREAK
      ' Otherwise, go to the grand-parent, and so on...
      treeview2.MoveBack() ' Returns to the parent
    LOOP
  ENDIF

WEND  

It should enumerate all treeview items...

This algorithm is useless in gb.gtk, as the TreeView.MoveBelow() already 
implements this algorithm. In gb.qt, TreeView.MoveBelow() uses a qt method 
that seems to not be reliable. The gb.gtk algorithm must be put in the gb.qt 
component, but I didn't do that yet...

Regards,

-- 
Benoit Minisini




More information about the User mailing list