This has been one of those user functionalities which I attacked sometime last year and now that I’ve had it placed into the framework, I feel that its been tested and works quite well. The frustration I had with listboxes where you do a sort (lets take iTunes for example) on Artist and lets say you know the name of the song. The list of the titles is in some random (or possibly the date added) order. What I’ve wanted to do, is to sort on the title, but to keep the artist sort. Its the same thing as doing a database query and using “order by artist, title”.

The following code is written in RealBasic and is by no means syntactically correct. Its only to show how it can be done.



lastString = me.cell(1, lastSortedColumn)

for i = 1 to me.listcount - 1
compareString = me.Cell(i, lastSortedColumn)

if lastString <> compareString then
self.Sort(lastPOS, i - 1)
lastPOS = i
lastString = me.Cell(lastPOS, lastSortedColumn)
end
next

The implementation most probably isn’t the fastest, but I haven’t noticed any speed issues with it yet. The idea is that you should know which column you’ve sorted on (lastSortedColumn), and when holding down a key, like the command key, to run through your listbox and sort the rows where the artists are the same. Its not difficult to do, and is a big time saver.

Written by Milton Lai

Leave a Comment

Your email address will not be published. Required fields are marked *