TreeView custom sort?

Richard Gaskin ambassador at
Sat Dec 10 13:33:52 EST 2016

Tore Nilsen wrote:

 > Could you build the initial array with the object names as keys, add
 > the layer numbers as part of the information you store about each
 > element,  then sort the array by layer numbers and set the array of
 > the tree view widget to the sorted array?

Ah, but arrays aren't sortable per se.

We can sort the keys of an array, but what we're doing there is sorting 
a delimited chunk.

Associative arrays have no internal representation of order, so no 
matter what I do with the keys the array itself will remain a hash table 
of unpredictable order.

I could prepend the top-level array key with a number, but this has two 

1. Not being purely numeric, it can only sort alphabetically, producing 
things like this:

     1 First item
     11 Eleventh item
     2 Second item

2. I'd prefer not to have the numbers visible to the user at all, since 
they would be just an artifice used for sorting and have no semantic 
meaning in my UI.

If the TreeView offered options for using custom sort functions that 
might work well, esp. if I could alter keys as it goes so I could remove 
the numeric portion.  But at the moment I don't believe it does.

  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  Ambassador at      

More information about the use-livecode mailing list