|
Technical answers from the trenches |
|
Using Lists to Limit Field Values
| ||||
Posted: 7 February 2003 |
||||
  |
Applies to: All versions |
|||
  |
Audience: Intermediate |
|||
Question: How do I prevent users from entering values that aren't in the lists of my combo boxes?Answer: Add code to the field object's (not the list object's) canDepart event that compares the value in the field to the values in the list, as shown in the following code sample: method canDepart(var eventInfo MoveEvent)
var
siCounter,
siIndexNo smallInt
uiListObj uiObject
astrNames Array[] String
endVar
; Step 1: Check for a blank value
; Remove this to require a value.
if self.isBlank() then
return
endIf
; Step 2: locate the list object
self.enumObjectNames( astrNames )
for siCounter from 1 to astrNames.size()
uiListObj.attach( astrNames[ siCounter ] )
if uiListObj.class = "List" then
quitLoop
endIf
endFor
; Step 3: compare the field value
; to the list values.
siIndexNo = -1
for siCounter from 1 to uiListObj.List.Count
if lower( self.Value ) = (lower( uiListObj.List.Value ) then
siIndexNo = uiListObj.List.Selection
quitLoop
endIf
endFor
; Step 4: Display an error if not match was
; found.
if siIndexNo = -1 then ;// invalid selection
msgStop( "Invalid Option", Self.Value +
" is not a valid choice. Please " +
"choose one from the list or Press " +
"Esc to cancel." )
eventInfo.setErrorCode( cannotDepart )
endIf
endMethodWhile this seems complicated, it's a very straightforward approach, one that doesn't require much design work (e.g. one that doesn't force you to consistently name your list objects.) The basic process is:
You can use similar code to let the user add new values to the list. For example, if you populate your list dynamically, you may want to let your users modify list sources based on tables. To do this, modify Step 4 accordingly. Notes and Tips
|
|||
|
||||||||
|
Copyright © 2000-2004, techtricks.com; All Rights Reserved. Acknowledgements, Disclaimers, Terms and Conditions. |
||||||||
|
Article last updated on 31 May 2003
|
||
|
|
||
|
[- End -]
|