[Gambas-user] Save Treeview Structure to table... mission accomplished...
sbungay
sbungay at ...981...
Tue Mar 6 06:34:36 CET 2007
I did not use recursion as I would have liked to. I even tore apart
an old VB6 app I wrote years ago that did this same job (traversing the
tree) using recursion but the code wouldn't port, the treeviews differ
too much in their properties and methods.
Since the treeview does not present itself as a doubly linked list I
set up a class and collection to do the job. This makes things a little
clumsy but it works.
The class file "ClassTreeView"
PUBLIC NodeKey AS String
PUBLIC ParentKey AS String
Each time a node is added to the treeview the class gets populated
with the key that was added and the key that it was added to
(child/parent). That class then gets added to the collection. The
Collection is indexed using the same key as the treenode that was just
added. Once you have any treenode key you can get parentkey information
from the collection. I could have done away with the collection but
thought there might be additional information to preserve in the future,
and expanding the class to hold more data is relatively easy, adding the
additional data to the collection requires minimal code changes.
The tree structure is preserved in the collection, you can walk the
collection and persist the structure to the table, or you can use the
little loop that Timothy sent in;
REPEAT
TreeView.Item.Expanded = TRUE ' Ensure all items are visible.
UNTIL TreeView.MoveBelow()
and combine that with the information in the collection to save the
structure.
Job done.
Steve.
More information about the User
mailing list