[Gambas-user] Treeview HELL...

timothy timothy.marshal-nichols at ...247...
Sun Mar 4 09:24:39 CET 2007


> -----Original Message-----
> From: gambas-user-bounces at lists.sourceforge.net [mailto:gambas-user-
> bounces at lists.sourceforge.net] On Behalf Of sbungay
> Sent: Sunday, 04 March 2007 01:40 AM
> To: GambasList
> Subject: [Gambas-user] Treeview HELL...
> 
>    I'm trying to iterate through a treeview, the goal is to store the
> treeview structure to a table (thats the easy part), the question is
> 'HOW can I traverse all nodes of a treeview using it's own methods?'
> 
>    The sample treeview control has a total of 5 nodes. One root node
> which has two children and each child has a child (5 nodes in all)
> 
>    Treeview1.Count returns a value of one (I expected 5)
> 
>    Treeview1.movenext seems to do.. umm.. nothing at all.
> 
>    .MoveChild also seems to do nothing.
> 
> For example, the following code;
> 
> WITH TreeView1
>       .MoveFirst
>       message.info (.Item.Key & ", " & .Item.text)
>       .MoveNext
>       message.info (.Item.Key & ", " & .Item.text)
> END WITH
> 
>    yields two messages with exactly the same information in them.
> 
> 
> Steve.
> 
> --You are in a maze of twisty little passages all alike.
> 
> 


This example saves the content of a treeview to a file. Thought it takes
no account of the hierarchy in the treeview: 

' Save the TreeView content to a csv text file
PUBLIC SUB ToolButtonSave_Click()
  DIM csvFile AS File
  IF TreeViewItems.Count = 0 THEN
    Message.Info("There are no items to save")
    RETURN
  END IF
  Dialog.Filter = ["*.csv", "Comma Separated Variable", "*.txt", "Text
Files", "*", "All Files"]
  IF Dialog.SaveFile() THEN RETURN
  ' Open the file as CREATE for writing to.
  ' If the file does not exist it will be created and opened.
  ' If the file does exist then the file is cleared and opened.
  OPEN Dialog.Path FOR CREATE AS #csvFile
  ' For each item in the TreeView
  TreeViewItems.MoveFirst()
  REPEAT
    PRINT #csvFile, Quote(TreeViewItems.Item.Key) & "," &
Quote(TreeViewItems.Item.Text)
  UNTIL TreeViewItems.MoveBelow()
  CLOSE #csvFile
CATCH
  Message.Info("<b>Cannot save items:</b><br>" & Dialog.Path & "<hr>" &
Error.Text)
  ' Make sure the file is closed. If the file is already closed
  ' or a null object then TRY will make sure we do not raise an error.
  TRY CLOSE #csvFile
END




Thanks

8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>









More information about the User mailing list