Date: 02-16-2022
Return to Index
created by gbSnippets
'Primary Code:
'Credit: Pierre Bellisle
Function SetTopItem(hListview As Dword, index As Long) As Long
Local ListviewItemRect As RECT, ListviewPixelItemHeight, ListviewPixelScrollPosY As Long
SendMessage(hListview, %LVM_GetItemRect, 0, VarPtr(ListviewItemRect))
ListviewPixelItemHeight = ListviewItemRect.nBottom - ListviewItemRect.nTop
ListviewPixelScrollPosY = GetScrollPos(hListview, %SB_Vert) * ListviewPixelItemHeight
SendMessage(hListView, %LVM_Scroll, 0, index * ListviewPixelItemHeight - ListviewPixelScrollPosY)
End Function
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%IDC_ListView = 500
%IDC_Button = 501
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "ListView Test",300,300,240,200,%WS_OverlappedWindow, 0 To hDlg
Control Add Button, hDlg, %IDC_Button, "Set 10 as Top", 125,10,100,20 '
CreateListView
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button : SetTopItem GetDlgItem(hDlg, %IDC_ListView), 10-1 '0-based index
End Select
End Select
End Function
Sub CreateListView
Local i As Long
Control Add ListView, hDlg, %IDC_ListView, "", 10,10,100,180
ListView Insert Column hDlg, %IDC_ListView, 1, "Data", 80, 0
For i = 1 To 100
ListView Insert Item hDlg, %IDC_ListView, 1, 0, Str$(101-i)
Next i
End Sub
Function SetTopItem(hLV AS Dword, index AS Long) AS Long
Local rc AS RECT
SendMessage(hLV, %LVM_GetItemRect, 0, VarPtr(rc))
SendMessage(hLV, %LVM_Scroll, 0, (index - GetScrollPos(hLV, %SB_Vert)) * (rc.nBottom - rc.nTop))
End Function
'gbs_01125
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm