LV_Group() v0.04 updated 2012/02/18
notes: should be stdlib compliant, only tested in _Basic, and unicode surely won't work as-is, may add features as i use it (header click re-grouping comes to mind), won't handle multiple LV's as is but will be fixed
Simple Example (run in a folder with some files around):
#SingleInstance, Force #NoEnv SetWorkingDir, %A_ScriptDir% Gui Add, ListView, w400 r30 gLVAction,Filename|Ext|Size [mb] LV_ModifyCol(1,250) LV_ModifyCol(2,60) LV_ModifyCol(3,"60 Integer") Loop, *.* { SplitPath A_LoopFileName,,,,NameWithoutExt Row:=LV_Add(""" " . DefaultCheck . " """,NameWithoutExt,A_LoopFileExt,Round(A_LoopFileSize/1024/1024)) LV_Group(Row,A_LoopFileExt) } Gui Show,,Group View Test Return LVAction: If (A_GuiEvent = "ColClick") { LV_Group("Delete") Loop, % LV_GetCount() { LV_GetText(_,A_Index,A_EventInfo) ;get text of clicked column as group to put it in LV_Group(A_Index,_) ;row, group, and hwnd of list view } } Return ; a little buggy on the size column for some reason GuiClose: GuiEscape: ExitAppFunction:
;—————————————————————————————————————————————————————— ;———————— LV_Group() 0.04 by gwarble 2012 ———————— ;————— ————— ;——— listview groups, or "show in groups" ——— ;—— https://ahknet.autohotkey.com/~gwarble/LV_Group/ —— ;—————————————————————————————————————————————————————— ; ; LV_Group([RowOrCommand, GroupName, ListViewHWnd]) ; ; RowOrCommand Row number to add to group, or 0 or "" to just add a group ; or Command to: ; "Enable" enable Group viewing ; (rows not assigned to groups will be hidden) ; "Disable" turn grouping off and revert to Report view ; "Toggle" toggle above options ; "Delete" turn off group view and delete all groups ; not yet implemented: delete groups, lots of LVM_'s, sortable by header, etc ; ; GroupName Name of group in which to add row ; or adds a group name without assigning a row if above=0 or "" ; in that case, multiple groups can be added as "Group1|Group2|..." ; ; ListViewHwnd hWnd of ListView control to work on... (listview option hwndListViewHwnd) ; will be remembered, so only needs to be used once if only using one LV ; not yet implemented: work on default LV when "" ; ; Return not sure what would be most useful ; 0 on error ; Group Number on success? group name? ;—————————————————————————————————————————————————————— LV_Group(Row, Group="`n", hWnd="") { static hWnd_, GroupCount, UnicodeHeader, Grouped static GroupList := "`n" hWnd_ := hWnd<>"" ? hWnd : hWnd_<>"" ? hWnd_ : "Default" If (hWnd_ = "Default") { ; PreviousLFWhwnd := WinExist() ; store for restoring after this Gui,+LastFound ; use default gui if no hwnd specified ControlGet,hWnd_,hWnd,,SysListView321 ; and save the hwnd so we don't have to find it again } ; IfWinExist, ahk_id %PreviousLFWhwnd% ; save and restore LastFound window? If (Row = "Enable") { SendMessage 0x109d,1,0,,ahk_id %hWnd_% ; LVM_ENABLEGROUPVIEW = 0x109d, l=1 to enable Grouped=1 } Else If (Row = "Disable") { SendMessage 0x109d,0,0,,ahk_id %hWnd_% ; LVM_ENABLEGROUPVIEW = 0x109d, l=0 to disable Grouped= } Else If (Row = "Return") { ;return a variables contents via: LV_Group("Return","GroupList") returns `n delimited list Return % %Group% } Else If (Row="Toggle") { If Grouped SendMessage 0x109d,0,0,,ahk_id %hWnd_% ; LVM_ENABLEGROUPVIEW = 0x109d, l=0 to disable Else SendMessage 0x109d,1,0,,ahk_id %hWnd_% ; LVM_ENABLEGROUPVIEW = 0x109d, l=1 to enable Grouped := !Grouped } Else If (Row="Delete") ; still need support to delete a group or unassign a row { SendMessage 0x10A0,0,0,,ahk_id %hWnd_% ; LVM_REMOVEALLGROUPS = 0x10A0 SendMessage 0x109d,0,0,,ahk_id %hWnd_% ; LVM_ENABLEGROUPVIEW = 0x109d, l=0 to disable Grouped:=GroupCount:="", GroupList:="`n" ; hwnd is still saved } ; Else If (Group="`n") AND (hWnd="") ; hWnd_ := hWnd := Row Else ; assuming an actual call and not a Command... { If !InStr(GroupList, "`n" Group "`n") { GroupList .= Group "`n" GroupCount++ If UnicodeHeader = VarSetCapacity(UnicodeHeader,100) Group%GroupCount%_:=Group VarSetCapacity( Group%GroupCount%, 96, 0) NumPut(96, &Group%GroupCount%, 0,"Int") ; LVGROUP_CbSize = 0 NumPut(0x11, &Group%GroupCount%, 4,"Int") ; LVGROUP_Mask = 4 ; LVGF_HEADER (flag 0x1) + LVGF_GROUPID (flag 0x10)?? DllCall("MultiByteToWideChar","UINT",0,"UINT",0,"UINT",&Group%GroupCount%_,"INT",-1,"UINT",&UnicodeHeader,"INT",strlen(Group%GroupCount%_)+1) NumPut(&UnicodeHeader, &Group%GroupCount%, 8,"Int") ; LVGROUP_PszHeader = 8 NumPut(GroupCount-1, &Group%GroupCount%, 24,"Int") ; LVGROUP_IGroupId = 24 SendMessage 0x1091, -1, &Group%GroupCount%,, ahk_id %hWnd_% ; LVM_INSERTGROUP = 0x1091 } If Row < 1 ;is not integer for LV_Group(0,"Group") to add group without assigning?? Return 1 ; successfully added group... not assigning any rows though StringTrimLeft, GroupList_, GroupList, 1 StringTrimRight, GroupList_, GroupList_, 1 StringSplit, Groups, GroupList_, `n Loop, %Groups0% If (Groups%A_Index% = Group) GroupNum:=A_Index VarSetCapacity( Group%Row%, 64, 0 ) NumPut(0x100, &Group%Row%, 0, "Int") ; LVIF_GROUPID (flag 0x100) NumPut(Row-1, &Group%Row%, 4, "Int") ; LVITEM_iItem = 4 NumPut(GroupNum-1, &Group%Row%, 40, "Int") ; LVITEM_iGroupId = 40??? SendMessage 0x1006, -1, &Group%Row%, , ahk_id %hWnd_% ; LVM_SETITEM = 0x1006 ; 0x104C unicode? SendMessage 0x109d,1,0,,ahk_id %hWnd_% ; LVM_ENABLEGROUPVIEW = 0x109d maybe this shouldnt be default, only with enable? Grouped=1 } Return 1 ; not sure whats useful yet to return, group number? name? }Help:
RowOrCommand Row number to add to group, or 0 or "" to just add a group
or Command to:
"Enable" enable Group viewing
(rows not assigned to groups will be hidden)
"Disable" turn grouping off and revert to Report view
"Toggle" toggle above options
"Delete" turn off group view and delete all groups
GroupName Name of group to add to LV, and group in which to add row
or adds a group name without assigning a row if above=0 or ""
in that case, multiple groups can be added as "Group1|Group2|..."
ListViewHwnd hWnd of ListView control to work on... (listview option hwndListViewHwnd)
will be remembered, so only needs to be used once if only using one LV
feedback welcome, i haven't seen much use of this listview ability on here but some may find a use for it... and hopefully some unicode/_L/64-bit gurus can help out with a modern version
- gwarble
thanks: <!-- m -->http://www.autohotke...pic.php?t=52485<!-- m -->
edit: v.04 update, see latest posts