TopIndex, TopItemId

These properties tell you which item in a list or combo box is at the top of the displayed list. This is one of those things people were always trying to figure out how to do in FoxPro 2.x but it couldn't be done. In Visual FoxPro, not only can you do it, but it's as simple as checking a single property!For lists only, you can change these properties to change the display.

Usage

lstList.TopIndex = nIndexOfTopItem
nIndexOfTopItem = oObject.TopIndex
lstList.TopItemid = nItemIdOfTopItem
nItemIdOfTopItem = oObject.TopItemid
For the difference between an Index and an ItemId, see the entry for AddItem.

The docs through VFP 5.0a say you can change this property for both combos and list boxes. 'Tain't so. The docs for VFP 6 say that TopIndex is read-only at runtime, while TopItemId is read-write. That's wrong, too. For VFP 7, the docs have changed yet again, but they're still wrong. Now they say that these properties are read-only at runtime and unavailable at design-time.

For combos, these properties are read-only. That seems right to us. The nature of combo boxes is that they always open with the current value displayed in the visible portion of the scrollable part, so the ability to change the top item doesn't make sense.

For lists, you can (and always have been able to) change these properties at runtime. They're read-only at design-time. That's all acceptable (though we're not sure why you can set these in the Property Sheet).


Example

frmMyForm.lstMyList.TopItemId = 37

See Also

AddItem, ComboBox, ListBox, ListIndex, ListItemId


Back to Table of Contents

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