O$: Tree list

David Wieland dwieland at approis.com
Wed Apr 29 22:39:52 EDT 2009

I use the following technique (based on a synthesis of Omnis documentation fragments) to build a tree list based on a schema:

[lTreeList is first loaded by a standard method.]

;  Combine columns to provide a concise tree (which OmnisSQL can't do)
Calculate %LN as lTreeList.$linecount
For lTreeList.$line from 1 to %LN step 1
Calculate lTreeList.//Student.LastName// as con(lTreeList.//Student.LastName//,", ",lTreeList.//Student.FirstName//)
Calculate lTreeList.//Student.FirstName// as con(lTreeList.//Enrollment.StartDate//,"|",lTreeList.//Enrollment.ID//)
End For

;  Convert relational list to flat in preparation for further manipulation
Do $cinst.$objs.lstLessonTree.$setnodelist(kRelationalList,0,lTreeList)
Do $cinst.$objs.lstLessonTree.$getnodelist(kFlatList,0,lTreeList)

;  Expand all nodes; move enrollment ID to $ident
Calculate %LN as lTreeList.$linecount
For lTreeList.$line from 1 to %LN step 1
Do lTreeList.C8.$assign(kTREEnodeExpanded)
Do lTreeList.C6.$assign(0)     ;; default $ident (not actually used)
If pos("|",lTreeList.C4)
Calculate #S1 as con(style(kEscStyle,kBold),lTreeList.C4)
Do lTreeList.C4.$assign(strtok("#S1","|"))
Do lTreeList.C6.$assign(strtok("#S1","|"))     ;; $ident (Enrollment ID)
Do lTreeList.C9.$assign(kDarkRed)     ;; to stand out
End If
End For

Do $cwind.$objs.lstLessonTree.$clearallnodes()
Do $cinst.$objs.lstLessonTree.$setnodelist(kFlatList,0,lTreeList)

This seemed a lot cleaner and more compact to me than looping.  Note that my application uses this tree list "as is", just for presentation and navigation, without allowing a user to directly edit it.  That might require something more complex.

David Wieland
Appro Information Systems
Kars (Ottawa), Ontario, Canada
(613) 692-4870
dwieland at approis.com

----- Original Message ----- 
From: "Andreas Pfeiffer" <andreas at familiepfeiffer.de>
To: "OmnisDev List - English" <omnisdev-en at lists.omnis-dev.com>
Sent: Wednesday, April 29, 2009 7:17 AM
Subject: Re: O$: Tree list

| Christine,
| Note that you can use $setnodelist for an individual sub branch as  
| well. On of the parameter just receives the reference to the node  
| where you want to add the sub branch.
| Kindest regards,
| Andreas
| Am 29.04.2009 um 01:13 schrieb Christine Penner:
| > I'm trying to build a dynamic tree list. There is a couple of ways  
| > to do that and I'm looking for everyones opinion which is best.
| >
| > I will be passing 2 lists. One with the columns (levels) I want in  
| > the tree. Including the field name and title.
| > The other will be the list of data.
| >
| > Currently all trees we use have only 3 levels. There could be more  
| > but not many. The data list could be large (possibly thousands).
| >
| > No matter how I do it I will have to walk through both the lists.  
| > Here are the 2 options I have come up with.
| >
| > 1. Add nodes one at a time using $add().
| > 2. Build a list (using the kFlatList form) and use $setnodelist()
| >
| > Christine Penner
| > Ingenious Software
| > 250-352-9495
| > christine at ingenioussoftware.com
| > _____________________________________________________________
| > Manage your list subscriptions at http://lists.omnis-dev.com

More information about the omnisdev-en mailing list