Hi fellow programmers,
As a effort to give back to the community for its help to me, I thought I
should share a piece of code that can be very helpful.
I found that I could not use a hierarchical list as a ‘choice list’ in a
listbox’s column. when clicked, only the top-level items show.
So I decided I needed to create a hierarchical menu from a list that could be
used within an OBJECT SCRIPT.
So here it is:
// ListToMenu(ListRef) --> menuRef
// caller must delete the menuRef after use
// NOTE: THIS IS CALLED RECURSIVELY FOR HANDLING CHILD LISTS ****
C_LONGINT($1)
C_TEXT($0)
$last:=Count list items($1) // the number of items in the list
$menuRef:=Create menu // we need to do this at the beginning as we will be
appending items to it.
For ($i;1;$last)
GET LIST ITEM($1;$i;$itemRef;$itemText;$subList;$expanded)
If ($subList>0) // there is a sublist?
$subMenu:=ListToMenu ($subList)
APPEND MENU ITEM($menuRef;$itemText;$subMenu;*)
Else
APPEND MENU ITEM($menuRef;$itemText;*)
SET MENU ITEM PARAMETER($menuRef;$i;$itemText) // so that the
TEXT of the name is returned when used with Dynamic pop up menu( )
End if
End for
$0:=$menuRef
In my case, I call it within an object script. Since the listbox source is a
collection, you will notice the object notation near the end of the script.
Adjust as needed.
// SCRIPT FOR COLUMN IN THE LISTBOX. The object name of the column is
“itemAction”. for some reason, I could not seem to get that programmatically so
that kind of bugged me as I like doing code that is less dependent. But I
decided just to give the name of the object at the beginning of the script:
$myObjName.
// the list has been set as the ‘choice list’ for this column, hence the call
to OBJECT Get list reference( ). Basically, you just need $theList to be the
list you want to use as the basis for the popup menu
$myObjName:="itemAction"
If (Form event=On Clicked)
$lbPtr:=OBJECT Get pointer(Object with focus)
LISTBOX GET CELL POSITION($lbPtr->;$col;$row) // the column & row that
was clicked on
$theList:=OBJECT Get list reference(*;$myObjName;Choice list)
$menu:=ListToMenu ($theList)
$answer:=Dynamic pop up menu($menu)
Form.col_Items[$row-1].action:=$answer
REDRAW($lbPtr->)
End if
— hopefully someone else finds this useful;
regards,
Chris Belanger
Innovative Solutions
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive: http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************