Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual FoxPro 9 SP2 ListBox Item Position

Status
Not open for further replies.

atamotua

IS-IT--Management
Jan 24, 2011
3
US
Mr Olaf, (or anyone who can answer this)
I have a list box populated by a cursor. The listbox can show about 10 items. My cursor ofcourse has more than 10 records, let's say 150 recs, so not all of them show in the ListBox. Ok, my question is this: Is there any way (any built in property, function - or code that i can write) to somehow get the absolute POSition of the selected item in the ListBox in reference to the (physical) ListBox itself? What I mean is this: I'm looking for the number that tells me where in the visual list box my selected record is LOCATED, AS IN: if the SECOND visible item in the listbox is selected, then the number i'm looking for is a 2. If visible item about half way onto the listbox is selected, then i'm looking for number 5 or 6, if the last visible item in the listbox is selected, then i'd need a 10. So the numbers i'm looking for range between 1 and 10, which is max visible items in this listbox. I've experimented with ItemData, ItemID, ItemIndex, etc... you name it, they all return a number which is similar to a RECORD number which ranges between 1 and 150 which is my max number of records in the Cursor - and that is not what i need. ************************* ... ALSO, could anyone shed some light on why so many properties that are similar for a listbox? for example: ListItemID, and ListIndex, ItemData, ItemIDData, ItemIdToIndex, IndexToItemId ??? thank you very much
Mike
 
Does the list's TopIndex property give you what you need?

As for why there are all these duplicated properties, here's what we said in the Hacker's Guide:

You've probably noticed that many of the properties and methods come in pairs. This is because there are two ways to address each item in a list or combo. The "Index" properties address items by their current position in the list. The "ItemId" properties address the items by a unique, permanent ID number assigned when the item is added to the list.

Tamar
 
I guess, atamotua, you want to know the index of the currently selected item in the ListBox control, whether this item is visible or not - correct?
If so (just the idea),

Code:
FOR I = 1 TO lstMyListBox.ListCount
   IF lstMyListBox.Selected(I)
      EXIT  && FOR...NEXT cycle
   ENDIF
NEXT I

and the value of the I is the index of the currently selected item.

HTH.


Regards,

Ilya
 
If I've understood the question right, you need to use a combination of .ListIndex and .TopIndex. For example:

Code:
WITH THISFORM.MyListBox
  lnPos = .ListIndex - .TopIndex + 1
ENDWITH

In this example, if there are ten visible items, and if the fifth visible item in selected, lnPos will contain 5.

Keep in mind that lnPos might be negative (if the selected item is above the visible range) or more than the number of visible items (if the selected item is below the visible range).

Does that answer the question?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top