Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "win32api.inc"
#Resource Manifest, 1, "xptheme.xml"
#Resource Icon, xplus "aplus.ico"
#Resource Icon, xminus "aminus.ico"
Type LVData
s As StringZ * 100 'string data
visible As Long 'visible
img As Long
End Type
%IDC_ListView = 500
%IDM_Collapse = 501
Global hDlg, hContext,hImgListEmpty,hImgListFull As Dword, D() As LVData
Function PBMain() As Long
Local i As Long
Dialog Default Font "Tahoma",10,0
Dialog New Pixels, 0, "ListView Test",300,300,300,300,%WS_OverlappedWindow, 0 To hDlg
CreateListView
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local x, y, iReturn As Long
Select Case Cb.Msg
Case %WM_InitDialog
CreateData
LoadData
CreateContextMenu
Case %WM_Size
Dialog Get Client hDlg To x,y
Control Set Size hDlg, %IDC_ListView, x,y
Case %WM_ContextMenu
x = Lo(Integer,Cb.LParam) : y = Hi(Integer, Cb.LParam)
iReturn = GetDlgCtrlID (Cb.WParam) 'get control ID
Select Case iReturn
Case %IDC_ListView '%IDC_ListView
TrackPopupMenu hContext, %TPM_LeftAlign, x, y, 0, Cb.Hndl, ByVal 0
End Select
End Select
End Function
Sub CreateListView
Control Add ListView, hDlg, %IDC_ListView, "", 0,0,300,300
ListView Set StyleXX hDlg, %IDC_ListView, %LVS_Ex_GridLines Or %LVS_Ex_FullRowSelect
ListView Insert Column hDlg, %IDC_ListView, 1, "Data", 300, 0
ImageList New Icon 1,16,24,3 To hImgListEmpty
ImageList New Icon 16,16,24,3 To hImgListFull
ImageList Add Icon hImgListFull, "xplus" '<--- 16x16 icons
ImageList Add Icon hImgListFull, "xminus" '<--- 16x16 icons
ListView Set ImageList hDlg, %IDC_ListView, hImgListFull, %lvsil_small
End Sub
Sub LoadData
Local i,iCount As Long
For i = 1 To UBound(D)
If D(i).visible Then
Incr iCount
ListView Insert Item hDlg, %IDC_ListView, iCount, 2, D(i).s
End If
Next i
End Sub
Sub CreateData
Local i As Long
ReDim D(1 To 40)
For i = 1 To 10 : D(i).s = "Rows" : D(i).visible = 1 : Next i
For i = 11 To 20 : D(i).s = "MoreRows" : D(i).visible = 1 : Next i
For i = 21 To 40 : D(i).s = "ExtraRows" : D(i).visible = 1 : Next i
End Sub
Sub CreateContextMenu
Menu New PopUp To hContext
Menu Add String, hContext, "Collapse", %IDM_Collapse, %MF_Enabled
End Sub
'gbs_00530
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm