These ListView methods return a reference to a ListItem object.
ListView.LineItem( index% )
ListView.ListItem( index% )
ListView.Item( variant )
ListView.GetFirstVisible
LineItem and ListItem return a reference to the specified index of the list item object (index starts with 1).
Item returns an item from the ListItems collection of the ListView control by either name or index.
GetFirstVisible returns a reference to the first object visible in the internal area of a control. A ListView control can contain more ListItem objects than can be seen in the internal area of the ListView control. You can use the reference returned by the GetFirstVisible method to determine the first visible ListItem object in List or Report view.
Debug.Show
~SetWindowPos(Debug.hWnd, 0, 205, 10, 600, 500, 0)
OpenW 1, 10, 10, 185, 300
Local n As Int32
Dim li As ListItem
Ocx ListView lv = "", 10, 10, 150, 200 : lv.View = 3
lv.ColumnHeaders.Add , , "Column1" : lv.ColumnHeaders(1).Width = PixelsToTwipX(130)
For n = 1 To 20
lv.ListItems.Add , "p" & Trim(n) , "Item " & n
Set li = lv.ListItem(n)
If Odd(n) Then li.Bold = True Else li.Italic = True
Next n
Ocx Timer lv_tim : lv_tim.Interval = 100 : lv_tim.Enabled = True
For n = 1 To 20 Step 5
// All the following produce the same result
Trace lv.LineItem(n).Text
Trace lv.ListItem(n + 1).Text
Trace lv.ListItems.Item("p" & Trim(n + 2)).Text // Item can take the Key string
Trace lv.Item(n + 3).Text // ...or the Index number
Trace lv(n + 4).Text
Next n
Do : Sleep : Until Me Is Nothing
Debug.Hide
Sub lv_tim_Timer
// In place of a 'Scroll' event which ListView is missing
Static Int32 sp : Local Int32 nsp
nsp = GetScrollPos(lv.hWnd, SBS_VERT)
If sp <> nsp
sp = nsp
Set li = lv.GetFirstVisible // - If this doesn't work see Known Issues below
' Const LVM_GETTOPINDEX = 4135
' Set li = lv(SendMessage(lv.hWnd, LVM_GETTOPINDEX, 0, 0) + 1)
Debug "Top Item: ";li.Text
EndIf
EndSub
Prior to OCX v2.33/2.34, GetFirstVisible returned Nothing (bug). If you experience this problem, you should download the latest version of GfaWin23.ocx; otherwise, use LVM_GETTOPINDEX instead as follows:
Const LVM_GETTOPINDEX = 4135
Set li = lv(SendMessage(lv.hWnd, LVM_GETTOPINDEX, 0, 0) + 1)
{Created by Sjouke Hamstra; Last updated: 04/03/2018 by James Gaite}