InteractiveChange, ProgrammaticChange

InteractiveChange and ProgrammaticChange give us the kind of control we've always wanted over changes in a form. These two alone made the upgrade from FoxPro 2.x to VFP worthwhile. InteractiveChange fires when a control's Value changes due to a user action. ProgrammaticChange fires when the Value changes because of something in code.

Usage

PROCEDURE InteractiveChange | ProgrammaticChange
[ LPARAMETERS nIndex ]
As with other events, nIndex is relevant only when a control array is involved, which is practically never.In the text-based controls, InteractiveChange fires every time the user presses a key. It's handy to do things like enabling a button as soon as there's a value, but use Valid if you want to validate the complete user input rather than each individual character. (You can do many of the same things in KeyPress, too.)These events are tied to the Value property of the control. When Value changes, the appropriate event fires. For combos and lists, changing DisplayValue programmatically also fires ProgrammaticChange. That's because changes to DisplayValue also affect Value.

For most controls, InteractiveChange doesn't fire when you re-choose the same item you just chose. For example, clicking the OptionButton that's already chosen in a group doesn't fire InteractiveChange for the OptionGroup. (Most of the time, this makes sense to us, since the Value of the control hasn't changed.) CommandGroups are the exception. Pressing a button in a CommandGroup always fires InteractiveChange for the group.


The place where the lack of firing is most counter-intuitive is with multi-select list boxes. If you click an item to select it, then Ctrl+click it to deselect it, InteractiveChange fires only the first time. Again, it's because Value hasn't changed, but, with multi-select, somehow it seems as if something must have changed. If this doesn't fire InteractiveChange, how about giving us an event it does fire?

In VFP 5.0a and earlier, changes to a combo's or list's Selected property do not fire ProgrammaticChange, even if doing so changes the object's Value. This is a bug, plain and simple. Fortunately, it was fixed in VFP 6.


Example

PROCEDURE InteractiveChange
* This might be the InteractiveChange procedure for a text box
* that is the only required input in a dialog.
* Once the user has entered a value, we enable the OK button.
ThisForm.cmdOK.Enabled = .T.
RETURN

See Also

Valid, Value


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .