REMOVE CLASS

BoundTo

This property was one of the most welcome additions to VFP 5. It lets you indicate whether a numeric ControlSource for a combo or list contains the position of the selected item or the value of the item.

Usage

lBindToNumericValue = oObject.BoundTo
The Value of combos and lists in Visual FoxPro can be either numeric or character. When the Value of a list or combo is initialized to a number or the ControlSource is numeric, by default, the position (Index) of the chosen item is stored. Even if the BoundColumn contains numeric data, it's the Index that gets stored.

However, lists and combos have the ability to draw their Value from a different field than the first one displayed and, in fact, to draw their Value from a column that isn't even displayed. This makes it possible to display a list of items, but store the unique IDs of those items. If you're using numeric (say, Integer) IDs, though, the default behavior of lists and combos presents a problem.

Enter BoundTo. If this property is set to .T., the actual numeric data is stored if both Value/ControlSource and the column referenced by BoundColumn are numeric. Leave BoundTo at .F. and you get the Index. If the column referenced by BoundColumn isn't numeric, but Value/ControlSource are, the Index is stored. If Value/ControlSource are character, then the content of the bound column is stored, as usual.

Note that you have to make up your mind ahead of time on this one. It's read-only at runtime.

Changes to BoundTo are not compatible with setting Value in the Property Sheet. If BoundTo is set to anything but the default (that is, shows bold in the Property Sheet), any value saved to the Value property is lost (though Value shows as non-default).


There's also a problem when BoundTo is set to .T. and the combo is bound to a numeric property of an ActiveX control (or at least some ActiveX controls). If we set BoundTo to .T. and set ControlSource to the ChartTitle.Orientation property of an MS Graph object in the Property Sheet, VFP bombs when we try to run the form. If we wait and assign the ControlSource in code, the form runs and the binding takes, but the current value of the combo doesn't display when the combo is closed.


Example
oForm = CREATEOBJECT("Form") * Add a list with character data in the first column * and numeric in the second, which is the bound column. OForm.AddObject("lstTwoCol","ListBox") WITH oForm.lstTwoCol    .Visible = .T.    .RowSourceType = 1   && Value    .RowSource = "Fred,17,Ethel,31,Lucy,2,Ricky,49"    .ColumnCount = 2    .ColumnWidths = "50,30"    .BoundColumn = 2    .BoundTo = .T.     && Treat column 2 as numbers. ENDWITH oForm.Show()

See Also

BoundColumn, ComboBox, ControlSource, ListBox, Value


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net