Wiki Home

Control Source


Namespace: VB
How do you retrieve the date value from a non VFP ActiveX control found in Windows? The control is a text box with a drop down calendar attached to it.

Control Source is used to specify the source of data to which an object is bound.
Syntax: Object.ControlSource[ = cName]

For controls, cName is a variable or field.

From the Hackers Guide:
For lists and combos, Control Source can be either character or numeric. When the Control Source is numeric, its interpretation is determined by the control's Bound To property. With the default .F. for Bound To, Value (and the Control Source) contains the position (or List Index) of the chosen item. To have a numeric value from the list's data stored in Value and the Control Source, you have to set Bound To to .T.

Although the Control Source is bound to the control's Value, the item named in Control Source doesn't get updated until after the control's Interactive Change is finished. Don't test the value of a Control Source until you reach the Valid event—if you need to test sooner, test the control's Value. In fact, it's better OOP to refer only to the control's Value in its methods and not mention the Control Source by name. If you reference the actual object named in Control Source, the code is no longer well encapsulated and the control is no longer as easily reusable.


The Control Source will not get updated if the control never loses focus, as when you exit the app while the control still has focus. To force an update, set the value to the value (".text1.value = .text1.value"). But where do you do this? One technique is to store the object to a global variable in the WHEN event of each control ("goLastObject = this"). Then include "goLastObject.value = goLastObject.value" in code that runs after READ EVENTS.

Applies To: Check Box, Column, Combo Box, Command Group, Edit Box, List Box, OLE Bound Control, OptionButton, OptionGroup, Spinner, Text Box.
Category VFP Control Properties
( Topic last updated: 2011.10.29 01:40:50 PM )