Date: 02-16-2022
Return to Index
created by gbSnippets
'An online ListView control tutorial may be found at:
'http://www.garybeene.com/power/pb-tutor-controls.htm
'Primary Code:
'Syntax: Control Add ListView, hDlg, id&, txt$, x, y, xx, yy [, [style&] [, [exstyle&]]] [[,] Call CallBack]
Control Add ListView, hDlg, 100, "", 10,10,175,75 '225
'Compilable Example: (Jose Includes)
'The following compilable code demonstrates a dialog with a single ListView control,
'using a resource file and three types of imagelists.
'The Dialog CallBack response to a column click demonstrated.
'Controls can also have a Callback function of their own.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Debug Error ON
#Debug Display On
#Include "win32api.inc"
#Include "commctrl.inc"
#Resource "gbsnippets.pbr"
Global hDlg As Dword 'main dialog handle
Global hLst1 As Dword, hLst2 As Dword, hLst3 As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "ListView Test",300,300,245,95,%WS_OverLappedWindow To hDlg
'create control
Control Add ListView, hDlg, 100, "", 10,10,175,75 '225
'create SMALL imagelist w,h,depth,size
ImageList New Icon 16,16,32,3 To hLst1
ImageList Add Icon hLst1, "x"
ImageList Add Icon hLst1, "y"
'create LARGE imagelist w,h,depth,size
ImageList New Icon 48,48,32,3 To hLst2
ImageList Add Icon hLst2, "xx"
ImageList Add Icon hLst2, "yy"
'create STATUS imagelist w,h,depth,size
ImageList New Icon 16,16,32,2 To hLst3
ImageList Add Icon hLst3, "check"
ImageList Add Icon hLst3, "blank"
'attach imagelist
ListView Set ImageList hDlg, 100, hLst1, %lvsil_small
ListView Set ImageList hDlg, 100, hLst2, %lvsil_normal
ListView Set ImageList hDlg, 100, hLst3, %lvsil_state
'columns hdlg, id&, col, "test", width, format
ListView Insert Column hDlg, 100, 1, "test1", 75, 0
ListView Insert Column hDlg, 100, 2, "test2", 75, 0
'rows hdlg, id&, row, image, "text"
ListView Insert Item hDlg, 100, 1, 1, "one" 'row 1, col1
ListView Insert Item hDlg, 100, 2, 2, "two" 'row 2, col1
'items hdlg, id&, row, col, "text"
ListView Set Text hDlg, 100, 1,2, "12" 'row1 col2
ListView Set Text hDlg, 100, 2,2, "22" 'row2 col2
ListView Set Mode hDlg, 100, 1 '0-icon 1-report 2-small 3-list
ListView Set StyleXX hDlg, 100, %lvs_ex_gridlines Or %lvs_ex_fullrowselect
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Notify AND CB.NmID = 100 AND CB.Nmcode = %LVN_ColumnClick Then
MsgBox "Selected!"
End If
End Function
'gbs_00097
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm