Inserts a group
#include <GuiListView.au3>
_GUICtrlListView_InsertGroup ( $hWnd, $iIndex, $iGroupID, $sHeader [, $iAlign = 0] )
| $hWnd | Control ID/Handle to the control |
| $iIndex | Index where the group is to be added. If this is -1, the group is added at the end of the list. |
| $iGroupID | ID of the group - non-negative integer value |
| $sHeader | Header text - the displayed name of the group |
| $iAlign | [optional] Alignment of the header text for the group: 0 - Left 1 - Center 2 - Right |
| Success: | the index of the item that the group was added to. |
| Failure: | -1. |
A group cannot be inserted into an empty control.
_GUICtrlListView_SetItemGroupID
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
Example()
Func Example()
GUICreate("ListView Insert Group (v" & @AutoItVersion & ")", 400, 300)
Local $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
; Enable extended control styles
_GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUISetState(@SW_SHOW)
; Set ANSI format
;~ _GUICtrlListView_SetUnicodeFormat($idListview, False)
; Load images
Local $hImage = _GUIImageList_Create()
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x0000FF, 16, 16))
_GUICtrlListView_SetImageList($idListview, $hImage, 1)
; Add columns
_GUICtrlListView_AddColumn($idListview, "Column 1", 100)
_GUICtrlListView_AddColumn($idListview, "Column 2", 100)
_GUICtrlListView_AddColumn($idListview, "Column 3", 100)
; Add items
_GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1, 1)
_GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2, 2)
_GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1, 2)
_GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2)
; Build groups
_GUICtrlListView_EnableGroupView($idListview)
_GUICtrlListView_InsertGroup($idListview, -1, 1, "Group 1")
_GUICtrlListView_InsertGroup($idListview, -1, 2, "Group 2")
_GUICtrlListView_SetItemGroupID($idListview, 0, 1)
_GUICtrlListView_SetItemGroupID($idListview, 1, 2)
_GUICtrlListView_SetItemGroupID($idListview, 2, 2)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
#include <GUIConstants.au3>
#include <GuiListView.au3>
Global $_hGUI = 0, $_hListView = 00
Example()
Func Example()
; create GUI window
$_hGUI = GUICreate("Example")
; create ListView control
Local $idListview = GUICtrlCreateListView("", 10, 10, 350, 200)
$_hListView = ControlGetHandle($_hGUI, '', $idListview)
; Enable extended control styles
_GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUISetState(@SW_SHOW)
; Set ANSI format
;~ _GUICtrlListView_SetUnicodeFormat($idListview, False)
GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)
_GUICtrlListView_AddColumn($idListview, "Column 0", 100)
_GUICtrlListView_AddColumn($idListview, "Column 1", 100)
_GUICtrlListView_AddItem($idListview, "Row 0: Col 0", 0)
_GUICtrlListView_AddSubItem($idListview, 0, "Row 0: Col 1", 1)
_GUICtrlListView_AddItem($idListview, "Row 1: Col 0", 1)
_GUICtrlListView_AddSubItem($idListview, 1, "Row 1: Col 1", 1)
_GUICtrlListView_AddItem($idListview, "Row 2: Col 0", 2)
_GUICtrlListView_EnableGroupView($idListview)
_GUICtrlListView_InsertGroup($idListview, -1, 101, "GROUP 1")
_GUICtrlListView_InsertGroup($idListview, -1, 102, "GROUP 2")
_GUICtrlListView_SetItemGroupID($idListview, 0, 101)
_GUICtrlListView_SetItemGroupID($idListview, 1, 102)
_GUICtrlListView_SetItemGroupID($idListview, 2, 102)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $iMsg, $wParam
If $hWnd = $_hGUI Then ; check if Our GUI - in case you create multiple GUI - Window
Local $tItem = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
If $tItem.hWndFrom = $_hListView Then ; check if our ListView - in case you have few ListView on the same GUI - Window
Local $iItemSpec = $tItem.dwItemSpec ; ItemIndex for "RowElement", GroupID for "GroupElement"
If $iItemSpec >= 0 And $tItem.Code = $NM_CUSTOMDRAW And $tItem.dwItemType = $LVCDI_GROUP And $tItem.dwDrawStage = $CDDS_PREPAINT Then
Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tItem, "left"))
#Region ; create full row background (black) with a leading line (red)
$tRect.bottom = $tRect.top + 18
Local $hBrush = _WinAPI_CreateSolidBrush(0)
_WinAPI_FillRect($tItem.HDC, $tRect, $hBrush)
_WinAPI_DeleteObject($hBrush)
Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_SwitchColor(0xFF0000)) ; RGB to BGR
Local $oOrig = _WinAPI_SelectObject($tItem.HDC, $hPen)
_WinAPI_DrawLine($tItem.HDC, $tRect.left + 5, $tRect.top + 8, $tRect.right - 5, $tRect.top + 8)
_WinAPI_SelectObject($tItem.HDC, $oOrig)
_WinAPI_DeleteObject($hPen)
Local $aGroup = _GUICtrlListView_GetGroupInfo($tItem.hWndFrom, $iItemSpec)
#EndRegion ; create full row background (black) with a leading line (red)
#Region ; repaint the text with your own color (dark blue) and your own background (light blue) - on the previously created full row background
_WinAPI_SetBkColor($tItem.HDC, _WinAPI_SwitchColor(0x55AAFF)) ; RGB to BGR
_WinAPI_SetBkMode($tItem.HDC, $OPAQUE)
_WinAPI_SetTextColor($tItem.HDC, _WinAPI_SwitchColor(0x0000FF)) ; RGB to BGR
$tRect.left += 20
_WinAPI_DrawText($tItem.HDC, " " & $aGroup[0] & " ", $tRect, $DT_LEFT)
#EndRegion ; repaint the text with your own color (dark blue) and your own background (light blue) - on the previously created full row background
Return $CDRF_SKIPDEFAULT
EndIf
EndIf
EndIf
EndFunc ;==>WM_NOTIFY