Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
#Debug Error On
#Debug Display On
%Unicode=1
#Include "win32api.inc"
%IDC_ListView = 500
%IDC_Button = 501
Global hDlg, hListView As Dword, D() As String, XX(), N As Long
Function PBMain() As Long
Dialog Default Font "Arial Black", 36, 1
Dialog New Pixels, 0, "Virtual ListView", , , 600,600, %WS_SysMenu,, To hDlg
Control Add Button, hDlg, %IDC_Button, "Test", 10,5,200,50
Control Add ListView, hDlg, %IDC_ListView,"", 10,60,570,530, %WS_Child Or %WS_TabStop Or %WS_Visible Or %LVS_Report Or %LVS_OwnerData Or %LVS_SingleSel Or %LVS_NoColumnHeader
Control Handle hDlg, %IDC_ListView To hListView 'handle to ListView
ListView Set StyleXX hDlg, %IDC_ListView, %LVS_Ex_FullRowSelect Or %LVS_Ex_GridLines
ListView Insert Column hDlg, %IDC_Listview, 1, "", 100,0 'set headers
ListView Insert Column hDlg, %IDC_Listview, 2, "Data", 450,0 'set headers
Dialog Show Modal hDlg, Call CBProc
End Function
CallBack Function CBProc
Local iRow,iCol As Long, temp$
Local pLVDI As LV_DISPINFOW Ptr, tmp$$, rc As Rect
Local LVNT As NMItemActivate Ptr
Select Case Cb.Msg
Case %WM_InitDialog
N = 5
MakeListViewData
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button : MakeListViewData
End Select
Case %WM_Notify
Select Case Cb.NmId
Case %IDC_ListView
Select Case Cb.NmCode
Case %LVN_GetDispInfo
pLVDI = Cb.LParam
iCol = @pLVDI.item.iSubItem+1
iRow = @pLVDI.item.iItem+1
Select Case iCol
Case 1 : tmp$$ = IIf$(XX(iRow),"X"," ")
Case 2 : tmp$$ = D(iRow)
End Select
@pLVDI.item.pszText = StrPtr(tmp$$) 'text sent to ListView
Case %NM_Click
'putting x in first column
LVNT = Cb.LParam
iRow = @LVNT.iItem+1 'row being asked for
iCol = @LVNT.iSubItem+1 'sub item being asked for (columns)
Select Case iCol
Case 1
XX(iRow) Xor= 1
ListView_GetSubItemRect hListView, iRow-1, iCol-1, %LVIR_Bounds, rc
InvalidateRect hListView, rc, %False
End Select
End Select
End Select
End Select
End Function
Sub MakeListViewData
Local i,j As Long
If N = 5 Then N = 7 Else N = 5
ReDim D(N)
ReDim XX(N)
For i = 0 To UBound(D)
D(i) = "Row" + Str$(i)
Next i
ListView_SetItemCountEx(hListView, UBound(D), %LVSICF_noInvalidateAll) 'max rows
ListView_SetItemState hListView, 0, %LVIS_Focused, %LVIS_Focused '<--- keyboard synchronizing code
Control ReDraw hDlg, %IDC_ListView
End Sub
http://www.garybeene.com/sw/gbsnippets.htm