Listing collections of collections in a tree

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Listing collections of collections in a tree

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:47 pm

by Jason >> Wed, 29 Oct 2003 6:59:16 GMT

hey
Does anyone know how to list collections of collections in a tree (listbox)

eg, John has two children who each have one child
thus each person has a myChildren collection.
John
|---Bill
| |---Sarah
|---Bob
|--- William

But I want it to work like the normal list collection, where once an item in the list is selected, the itemObject property of the listbox is set to that selected item.
For a better example look in Jade. On the left where it displays classes and subclasses, and when you click on a class all the attributes/references/methods for that class is shown.

Thats what I want to do. Any ideas?


---

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.530 / Virus Database: 325 - Release Date: 22/10/2003

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Listing collections of collections in a tree

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:47 pm

by allistar >> Wed, 29 Oct 2003 7:27:25 GMT

Hi John,
You need to set the "itemLevel" property in the list box accordingly.

I.e. to do what you want above you could do this:

listPerson(person: Person; level: Integer);
//recursive method for diaplying a person and all decendants
vars
iter: Iterator;
child: Person;begin

listBox.addItem(person.name);
listBox.itemObject[listBox.newIndex()] := person;
listBox.itemLevel[listBox.newIndex()] := level;
iter := person.allChildren.createIterator();
while (iter.next(child)) do
listPerson(child, level + 1);
endwhile;
epilog
delete iter;
end;

You would call this with the "root" person and pass through "1" as the level. Note that I am not in front of JADE at the moment, so that is off the top of my head. It may or may not compile straight away :-) You will also probably want to open up the tree by default by setting the "itemExpanded" property to true (this is a BooleanArray).

Hope this helps,
Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 11 guests

cron