I'm trying to setup a listview using groups. And it seems to work, but after leaving the procedure which assigns the listview items to groups the program just hangs. Also the listview doesn't update (no groups are shown, only a blank window). Tested using PB 5.21LTS, x64, unicode.
Here's the code:
Code: Select all
Procedure MainviewShowGrouped(hWnd.i, iColumn.i)
; --- groups the items of a listview
; ---
; --- Parameter:
; --- hWnd.i = window (listview) handle
; --- iColumn.i = column to group by
Protected iNumberOfEntries.i
Protected iGroupFound.i ; used to determine if a group already exits -> true, then no new group is added
Protected iCounter.i
Protected sItem.s ; holds the item text
Protected _lvitem.LVITEM
Protected _lvgroup.LVGROUP
Protected NewList sGrouplist.s() ; stores the different groups we use
SendMessage_(hWnd, #LVM_ENABLEGROUPVIEW , #True, 0)
_lvGroup\cbSize = SizeOf(LVGROUP)
_lvGroup\mask = #LVGF_HEADER | #LVGF_GROUPID | #LVGF_ALIGN | #LVGF_STATE ; set fields of the LVGROPU structure that are to be used later on
_lvgroup\state = #LVGS_COLLAPSIBLE
; -> build the Grouplist
iNumberOfEntries = SendMessage_(hWnd, #LVM_GETITEMCOUNT, #Null, #Null) - 1
Debug "Entries = " + iNumberOfEntries
Protected *Buffer
*Buffer = AllocateMemory(512)
If Not (*Buffer)
ProcedureReturn
EndIf
_lvitem\mask = #LVIF_TEXT
_lvitem\iSubItem = iColumn
_lvitem\pszText = *Buffer
_lvitem\cchTextMax = 255
For iCounter = 0 To iNumberOfEntries
SendMessage_(hWnd, #LVM_GETITEMTEXT, iCounter, @_lvitem)
sItem = PeekS(_lvitem\pszText)
Debug "BuildGroups/sItem = " + sItem
ResetList(sGrouplist())
While NextElement(sGrouplist())
iGroupFound = #False
If sGrouplist() = sItem
iGroupFound = #True
Break
EndIf
Wend
If Not iGroupFound
AddElement(sGrouplist())
sGrouplist() = sItem
EndIf
Next
Debug "# of groups = " +ListSize(sGrouplist())
; --- set groups
iCounter = 0
ResetList(sGrouplist())
While NextElement(sGrouplist())
_lvgroup\pszHeader = @sGrouplist()
_lvgroup\cchHeader = Len(sGrouplist())
_lvgroup\iGroupId = iCounter
_lvgroup\uAlign = #LVGA_HEADER_LEFT
SendMessage_(hWnd, #LVM_INSERTGROUP, 0, @_lvgroup) ; wParam = Index where the group is being added (-1 -> at the end) // lParam = Pointer to LVGROUP
iCounter + 1
Wend
; --- assign the lv items to the groups
For iCounter = 0 To iNumberOfEntries
FillMemory(@_lvitem, SizeOf(LVITEM)) ; clear the structure
_lvitem\mask = #LVIF_TEXT ; get the text of the cell
_lvitem\iSubItem = iColumn
_lvitem\pszText = *Buffer
_lvitem\cchTextMax = 255
SendMessage_(hWnd, #LVM_GETITEMTEXT, iCounter, @_lvitem)
sItem = PeekS(_lvitem\pszText)
Debug "Assign items to groups/sItem = " + sItem
ResetList(sGrouplist())
While NextElement(sGrouplist())
If sItem = sGrouplist()
Break
EndIf
Wend
FillMemory(@_lvitem, SizeOf(LVITEM)) ; clear the structure
_lvitem\mask = #LVIF_GROUPID ; set item to specific group
_lvitem\iItem = iCounter
_lvitem\iGroupId = ListIndex(sGrouplist())
Debug "SendMessage/setitem = " + SendMessage_(hWnd, #LVM_SETITEM, #Null, @_lvitem)
Next
FreeMemory(*Buffer)
EndProcedure
OpenWindow(99, 200, 200, 300, 300, "LV Group")
handleLV = ListIconGadget(#PB_Any, 0, 0, 300, 300, "Column 0", 50, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
For iCounter = 1 To 3
AddGadgetColumn(handleLV, iCounter, "Column " + Str(iCounter), 50)
Next
For iCounter = 1 To 5
AddGadgetItem(handleLV, -1, "Column 0 / " + Str(iCounter) + Chr(10) + "1" + Chr(10) + "Column 2 / " + Str(iCounter) + Chr(10) + "Column 3 / " + Str(iCounter) + Chr(10))
Next
For iCounter = 6 To 10
AddGadgetItem(handleLV, -1, "Column 0 / " + Str(iCounter) + Chr(10) + "2" + Chr(10) + "Column 2 / " + Str(iCounter) + Chr(10) + "Column 3 / " + Str(iCounter) + Chr(10))
Next
MainviewShowGrouped(GadgetID(handleLV), 1)
Debug "left procedure"
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Greetz,
Fenix

