Group III - Collapsible

Category: Controls - ListView

Date: 02-16-2022

Return to Index


 
'Compilable Example:  (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "win32api.inc"
 
#Resource Manifest, 1, "xptheme.xml"
 
#Resource Icon, xtop "top.ico"
#Resource Icon, xmid "mid.ico"
#Resource Icon, xbottom "bottom.ico"
#Resource Icon, xempty "empty.ico"
 
%IDC_Checks  = 500
%IDC_Drawings = 501
%IDC_ListView = 502
 
Global hDlg,hListView,hImgListFull,hImgListEmpty As Dword
Global CheckBoxes, Drawings As Long
 
Function PBMain() As Long
   Dialog New Pixels, 0, "ListView Test",300,300,200,250,%WS_OverlappedWindow To hDlg
   Control Add CheckBox, hDlg, %IDC_Checks, "CheckBoxes", 10,10,75,20
   Control Set Check hDlg, %IDC_Checks, %True
   Control Add CheckBox, hDlg, %IDC_Drawings, "Line Drawings", 95,10,100,20
   Control Set Check hDlg, %IDC_Drawings, %True
   CreateListView
   Dialog Show Modal hDlg Call DlgProc
End Function
 
CallBack Function DlgProc() As Long
   Select Case Cb.Msg
      Case %WM_Command
         Select Case Cb.Ctl
            Case %IDC_Checks
               Control Get Check hDlg, %IDC_Checks To CheckBoxes
               ListView Set StyleXX hDlg, %IDC_ListView, IIf(CheckBoxes, %LVS_Ex_CheckBoxes, 0)
            Case %IDC_Drawings
               Control Get Check hDlg, %IDC_Drawings To Drawings
               'line drawing
               If Drawings Then
                  ListView Set ImageList hDlg, %IDC_ListView, hImgListFull, %lvsil_small
               Else
                  ListView Set ImageList hDlg, %IDC_ListView, hImgListEmpty, %lvsil_small
               End If
         End Select
   End Select
End Function
 
Sub CreateListView
   Local LVStyle As Long
   LVStyle = %WS_TabStop Or %LVS_Report Or %LVS_AlignTop Or %LVS_NoColumnHeader
'   LVStyle = %WS_TabStop Or %LVS_Report Or %LVS_ShowSelAlways Or %LVS_AlignTop Or %LVS_NoColumnHeader
   Control Add ListView, hDlg, %IDC_ListView, "", 10,40,180,210, LVStyle, %WS_Ex_Left
   Control Handle hDlg, %IDC_ListView To hListView
   ListView_EnableGroupView hListView, %True
   ListView Set StyleXX hDlg, %IDC_ListView, %LVS_Ex_GridLines Or %LVS_Ex_CheckBoxes
 
   ImageList New Icon 1,16,24,3 To hImgListEmpty
   ImageList New Icon 16,16,24,3 To hImgListFull
   ImageList Add Icon hImgListFull, "xtop"         '<--- 16x16 icons
   ImageList Add Icon hImgListFull, "xmid"
   ImageList Add Icon hImgListFull, "xbottom"
   ListView Set ImageList hDlg, %IDC_ListView, hImgListFull, %lvsil_small
 
   ListView Insert Column hDlg, %IDC_ListView, 1, "Data", 180, 0
 
   AddGroup 1
   ListView Insert Item hDlg, %IDC_ListView, 1, 1, "Group 1 - Line 1"
   ListView Insert Item hDlg, %IDC_ListView, 2, 2, "Group 1 - Line 2"
   ListView Insert Item hDlg, %IDC_ListView, 3, 3, "Group 1 - Line 3"
   SetItemGroup 0,1 : SetItemGroup 1,1 : SetItemGroup 2,1
 
   AddGroup 2
   ListView Insert Item hDlg, %IDC_ListView, 4, 1, "Group 2 - Line 1"
   ListView Insert Item hDlg, %IDC_ListView, 5, 2, "Group 2 - Line 2"
   ListView Insert Item hDlg, %IDC_ListView, 6, 3, "Group 2 - Line 3"
   SetItemGroup 3,2 : SetItemGroup 4,2 : SetItemGroup 5,2
End Sub
 
Sub AddGroup(lGroup As Long)
   Local ListviewGroup As LVGROUP, sGroupHeader As WString
   sGroupHeader            = "Group" + Str$(lGroup)
   ListviewGroup.cbSize    = SizeOf(ListviewGroup)
   ListviewGroup.mask      = %LVGF_HEADER Or %LVGF_GROUPID Or %LVGF_ALIGN Or %LVGF_STATE
   ListViewGroup.nstate     = %LVGS_Collapsible
   ListviewGroup.pszHeader = StrPtr(sGroupHeader)
   ListviewGroup.cchHeader = Len(sGroupHeader)
   ListviewGroup.iGroupId  = lGroup
   ListviewGroup.uAlign    = %LVGA_HEADER_CENTER
   LISTVIEW_INSERTGROUP(hListview, lGroup, ListviewGroup)
End Sub
 
Sub SetItemGroup(iItem As Long, lGroup As Long)
   Local ListviewItem As LVITEMA
   ListviewItem.mask       = %LVIF_GROUPID
   ListviewItem.iItem      = iItem
   ListviewItem.iSubItem   = 0
   ListviewItem.iGroupId   = lGroup
   LISTVIEW_SETITEM(hListview, ListviewItem)
End Sub
 
 
'gbs_01246
'Date: 05-11-2013               


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm