Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "win32api.inc"
Type MyData
title As WStringZ * 100
status As Long
ptr As Long
revptr As Long
End Type
%IDC_ListView = 500
Global hDlg, hListView As Dword, D() As MyData
Function PBMain() As Long
Dialog New Pixels, 0, "Virtual ListView", , , 270,300, %WS_SysMenu,, To hDlg
MakeListViewData
Control Add ListView, hDlg, %IDC_ListView,"", 10,10,250,280, %WS_Child Or %WS_TabStop Or %WS_Visible Or %LVS_ShowSelAlways Or %LVS_Report Or %LVS_OwnerData Or %LVS_ShowSelAlways Or %LVS_SingleSel
Control Handle hDlg, %IDC_ListView To hListView 'handle to ListView
ListView Set StyleXX hDlg, %IDC_ListView, %LVS_Ex_CheckBoxes
ListView Insert Column hDlg, %IDC_Listview, 1, "Col 1", 115,0 'set headers
ListView_SetItemCountEx(hListView, 10, %LVSICF_noInvalidateAll) 'max rows
SendMessage (hListView, %WM_NOTIFYFORMAT, hDlg, %NF_REQUERY)
Dialog Show Modal hDlg, Call CBProc
End Function
CallBack Function CBProc
Local Col, Row As Long, pLVDI As LV_DISPINFOW Ptr
Select Case Cb.Msg
Case %WM_InitDialog
SetStatusValues
BuildPointers
Case %WM_Notify
Select Case Cb.NmId
Case %IDC_ListView
Select Case Cb.NmCode
Case %NM_Click
ListView Get Select hDlg, %IDC_ListView To Row
Dialog Set Text hDlg, "Row" + Str$(Row) + " is data from data element " + Str$(D(Row-1).revptr)
Case %LVN_GetDispInfo 'notification to ask for data
pLVDI = Cb.LParam 'pointer to LVDISPINFO structure for requested subitem
Row = @pLVDI.item.iItem 'row being asked for
@pLVDI.item.pszText = VarPtr(D(D(Row).ptr).title)
End Select
End Select
End Select
End Function
Sub MakeListViewData
Local i,j As Long
ReDim D(6)
For i = 0 To UBound(D)
D(i).title = "Row" + Str$(i)
Next i
End Sub
Sub SetStatusValues
D(0).status = 1
D(1).status = 1
D(2).status = 0
D(3).status = 0
D(4).status = 0
D(5).status = 1
D(6).status = 1
End Sub
Sub BuildPointers
Local i, j, MaxLines, EndReached, Skipped, LastSelected As Long
LastSelected = -1
For i = 0 To UBound(D)
If (D(i).status) And (i > LastSelected) Then
Incr MaxLines
D(i).ptr = i
D(i).revptr = i
LastSelected = i
Else
'Find next non-zero beyond the last selected element
EndReached = 1
For j = LastSelected+1 To UBound(D)
If D(j).status Then
Incr MaxLines
D(i).ptr = j
D(i).revptr = j
LastSelected = j
EndReached = 0
Exit For
End If
Next j
If EndReached Then Exit For
End If
Next i
ListView_SetItemCountEx(hListView, MaxLines, %LVSICF_noInvalidateAll) 'max rows
End Sub
'gbs_01251
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm