Hackers Guide to Visual FoxPro 7.0
List, ListItem
These two properties are arrays that give you access to the data in a list or combo box. These are very, very cool properties. They not only let you look up the information, but also let you change it when appropriate.| Usage | oObject.List( nIndex [, nColumn ] ) = cValue cValue = oObject.List( nIndex [, nColumn ] ) oObject.ListItem( nItemId [, nColumn ] ) = cValue cValue = oObject.ListItem( nItemId [, nColumn ] ) |
This.List[ This.ListIndex ] or even
ThisForm.lstMyList.ListItem[ ThisForm.lstMyList.ListItemId ]
| | On to what we think is pretty cool stuff. See that nColumn parameter? It works not only in a multi-column list, but any time the RowSource for the list has multiple columns. If your RowSourceType is 2 (Alias), you can access every column of the table or view the list is based on by specifying an appropriate value for nColumn. Same thing for a SQL statement (RowSourceType=3) or a Query (RowSourceType=4) or an Array (RowSourceType=5). |
What about changing items using these properties? You can do this only for lists or combos with RowSourceType set to 0 or 1. In other words, changes work only when the list of items really belongs to the control, not when it's based on some outside data. That's okay with us—in the other cases, we can just change the underlying data (and then call Requery to update the list).
You can disable an item in the list by preceding its text with a backslash ("\"). This technique works with RowSourceType = 0, 1 or 5. If an item needs to begin with a backslash and shouldn't be disabled, use two backslashes. Amazingly, you can even add items by simply assigning a value for an item that didn't exist before. Given how hard it is to figure out AddItem and AddListItem, directly manipulating List or ListItem may be a viable alternative.| Example | * Set a variable to the currently selected item. cCurValue = This.List[ This.ListIndex ] |
| See Also | AddItem, AddListItem, ComboBox, ItemData, ItemIdData, ListBox, ListCount, ListIndex, ListItemId, Requery |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.
Категории