Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Setting a Specific Index in a List Box when it loads by Sam Asghari
When dealing with GUIs, it is very natural to have lists where users can select a single item. For our project, we thought that it would be nice to have a particular item in the list pre-selected for the user when they open up the GUI. To do this requires a single line of code (but could take a while to find if you don't know what to search for.) Anyway, assume you have something like the following:
docs := SelectionInList new.
docs listHolder: ((UI.AspectAdaptor subject: sys sendsUpdates: true) forAspect: #doctors).
If we wanted to have the 5th doctor selected when the GUI is opened up, we would need to add the following line of code:
docs selectionIndexHolder value: 5.
The great power of this trick is seen when you are able to generate a particular index based on a current user/"state". For instance, for our project, we wanted a patients' doctor to be selected in the list of doctors when the patient info was being viewed (if the pre-selected doctor was changed, the patient would be assigned a new doctor). The code to handle this task was:
model doctor isNil ifFalse: [ sys doctors do: [:d | d uid = model doctor uid ifTrue: [idx := (c).] ifFalse: [c := c+1]]. self docs selectionIndexHolder value: idx.].
While this code probably isn't too useful for you in the way that it is presented, the idea of being able to search through an OrderedCollection, to find a desired index, and to properly set the correct index of the List in the GUI should be of some use!
Links to this Page
- Cases last edited on 30 July 2011 at 2:33 am by r59h132.res.gatech.edu
- Index of Individual Cases last edited on 3 May 2011 at 12:46 pm by r52h48.res.gatech.edu