Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox validation 2

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
1
18
GB
A dropdown listbox (Class Combo) is used to enter a single character (<space>,‘C’, ‘S’, ‘B’, ‘L’) credit status for a customer. where <space> indicates open credit, ‘C’ Cash only &c. The control has as its controlsource a field in the table being maintained, and its other properties include :

Format !
RowSource type 5 - Array
Style 0 – Dropdown combo

Its RowSource is set to an array aCredOptions

When the user clicks on the Down arrow and then clicks on one of the 5 rows of the dropdown (say, “S”), that works fine. The form shows the value “S” in the listbox and the corresponding description is also displayed.

If the user enters one of the five values into the control, that also works.

What is the best way of ensuring that the character entered into the listbox (if the user is working that way, rather than using the down-arrow) is valid? Is it a matter of putting code onto the KeyPress() event? At present I have this code :

Code:
*  cboCredit.Keypress()

LPARAMETERS nKeyCode, nShiftAltCtrl
LOCAL lChar
   lCHAR = UPPER(CHR(nKeyCode))
   IF !(lChar $ " BCLS") .AND. nKeycode > 48
      NODEFAULT
      RETURN
      ENDIF
   RETURN DODEFAULT(nKeyCode, nShiftAltCtrl)

Would welcome guidance - maybe I should be using a different control class . . . .

Thanks for your help.
 
if they are limited to those options change style to 'dropdown list' and the user won't be able to enter anything but these options and no validation will be necessary.

if i've misunderstood and some validation IS still necessary.... probably testing this.value in the .interactivechange event is best.

hth

n

 
Andrew, I would think that, if the user can only enter one of those five values, you shouldn't be using a dropdown combo, but rather a dropdown list. In other words, set the Style to 2. And set IncrementalSearch to .T.

That way, if they press something other than one of the legal values, it will simply be ignored, which is what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you both for these two prompt and helpful replies. I will check them out. Andrew
 
Have checked this out and it gives a cleaner interface to the user, as well as saving some code. - had never discovered this style option in a combo box. I have included this feature in several parts of the application After all these years . . . !

Thank you Nigel & Mike.
 
Problem solved, still lets get some terms straight:

Andrew Mozley said:
A dropdown listbox (Class Combo)

What you call a dropdown ListBox is a ComboBox (there also is no class combo, the base class name is ComboBox). Your description fits, what drops down looks like a listbox of items to pick from. But the main reason it's called combobox is because in the normal mode you know and knew all these years it's a combination of a textbox and a dropdown list. And as you now learned it has two modes.

It confused me you suddenly talked of a listbox here:
Andrew Mozley said:
that the character entered into the listbox

Because a Listbox, while it always displays all items for picking them and has no text entry textbox, it still also has a keypress event as it also supports incremental search when typing in items, too.

Anyway, yes, simply use the dropdown list style and there is no problem with entering a wrong character.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top