Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Listbox validation

Listbox validation

Listbox validation

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
   lCHAR = UPPER(CHR(nKeyCode))
   IF !(lChar $ " BCLS") .AND. nKeycode > 48
   RETURN DODEFAULT(nKeyCode, nShiftAltCtrl) 

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

Thanks for your help.

RE: Listbox validation

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.



RE: Listbox validation

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 Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Listbox validation

Thank you both for these two prompt and helpful replies. I will check them out. Andrew

RE: Listbox validation

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.

RE: Listbox validation

Problem solved, still lets get some terms straight:

Quote (Andrew Mozley)

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:

Quote (Andrew Mozley)

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close