Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code compiles only in PBWin10. To compile in PBWin9, remove these lines:
#Option AnsiAPI
SendMessage (hListView, %WM_NOTIFYFORMAT, hDlg, %NF_REQUERY)
'There is no PBWin9 equivalent to iPowerTime, with which to easily convert
'this snippet to PBWin9.
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "commctrl.inc"
%IDC_ListView = 500
Global hDlg, hListView As Dword, D() As String 'will put ListView data in D()
Function PBMain() As Long
Dialog New Pixels, 0, "Virtual ListView", , , 250,300, %WS_SysMenu,, To hDlg
Control Add ListView, hDlg, %IDC_ListView,"", 10,10,220,280, %WS_Child Or %WS_TabStop Or %WS_Visible Or %LVS_ShowSelAlways Or %LVS_Report Or %LVS_OwnerData 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 Insert Column hDlg, %IDC_Listview, 2, "Col 2", 115,0 'set headers
ListView_SetItemCountEx(hListView, 1000, %LVSICF_noInvalidateAll) 'max rows
SendMessage (hListView, %WM_NOTIFYFORMAT, hDlg, %NF_REQUERY)
GetSomeData
Dialog Show Modal hDlg, Call CBProc
End Function
CallBack Function CBProc
Local Col, Row As Long, pLVDI As LV_DISPINFOW Ptr, temp$$
Select Case Cb.Msg
Case %WM_Notify
Select Case Cb.NmId
Case %IDC_ListView
Select Case Cb.NmCode
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
Col = @pLVDI.item.iSubItem 'sub item being asked for (columns)
temp$$ = D(Row,Col)
@pLVDI.item.pszText = StrPtr(temp$$) 'text sent to ListView
End Select
End Select
End Select
End Function
Sub GetSomeData
Local i,j As Long
ReDim D(1000,1)
For i = 0 To 1000
D(i,0) = "Col1 - Row" + Str$(i)
D(i,1) = "Col2 - Row" + Str$(i)
Next i
End Sub
'gbs_00988
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm