[Gambas-user] enumerate treeview items

Christopher Brian Jack brian at ...1334...
Sat Oct 28 14:38:34 CEST 2006


On Thu, 26 Oct 2006, olinux wrote:

> Date: Thu, 26 Oct 2006 15:48:19 +0200
> From: olinux <olinux at ...289...>
> Reply-To: mailing list for gambas users
>     <gambas-user at lists.sourceforge.net>
> To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
> Subject: [Gambas-user] enumerate treeview items
>
> Is somebody to know how to enumerate items in a treeview like for each
> loop ????

Okay I have created a class that will implement iteration on a TreeView
object.  The class file itself is simple enough to use.  The class works
by specifying a TreeView host, an observer (ME works good in most cases)
and method basename (called on the observer as <basename>_next).

This class could be generalized to iterate over other things like
ListView and TableView but that is left as an exercise for anyone else.

NB: I was not able to find a way to get the name of the host object only
its type (TreeView in this case).  So you cannot currently use single
XXX_next method to observe iteration for more than one host (since there's
no way to know which host object you are receiving notificaiton for).

If the attachment comes through OK it includes a test form that uses the
iterator and dumps the resulting output.

The brief snippets below indicates the gist of using the class:

'We have a form containing a TreeView called tvTheTreeView
PRIVATE tviTheTreeView AS CIterateTreeView

PUBLIC SUB form_Open()
  tviTheTreeView=NEW CIterateTreeView(tvTheTreeView, ME, "tviMyIterator")
  ...
END

PUBLIC SUB form_Close()
  'keep this in or you get problems with circular referencing
  tviTheTreeView=NULL
END

PUBLIC SUB tviMyIterator_next(hostob AS TreeView, key AS String,
  state AS Integer)
  SELECT state
    CASE CIterateTreeView.IterBegin
      'called before iteration starts
    CASE CIterateTreeView.IterDone
      'called after iteration is complete
    CASE CIterateTreeView.IterVisit
      'called once for each .TreeViewItem visited
      'you have to use the key arg since .TreeViewItem
      'do not work for method parameter passing
  END SELECT
END

.=================================================.
|  Christopher BRIAN Jack aka "Gau of the Veldt"  |
+================================================='
| oevna at ...1544...
`=================================================-
Hi Spambots, my email address is sputnik at ...1334...
Hi Humans, my email address uses rot13 cipher
-------------- next part --------------
A non-text attachment was scrubbed...
Name: IterateTreeView.tar.bz2
Type: application/octet-stream
Size: 38297 bytes
Desc: IterateTreeView.tar.bz2
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20061028/df754237/attachment.obj>


More information about the User mailing list