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 <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPIGdi.au3> #include <WinAPIGdiDC.au3> #include <WinAPIHObj.au3> Global $g_hGUI = 0, $g_hListView = 00 Example() Func Example() ; create GUI window $g_hGUI = GUICreate("Example") ; create ListView control Local $idListview = GUICtrlCreateListView("", 10, 10, 350, 200) $g_hListView = ControlGetHandle($g_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) ; Load images Local $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, $COLOR_RED, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, $COLOR_GREEN, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, $COLOR_BLUE, 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 Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam If $hWnd = $g_hGUI Then ; check if Our GUI - in case you create multiple GUI - Window Local $tItem = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) If $tItem.hWndFrom = $g_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 + 15 Local $hBrush = _WinAPI_CreateSolidBrush($COLOR_BLACK) _WinAPI_FillRect($tItem.HDC, $tRect, $hBrush) _WinAPI_DeleteObject($hBrush) Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_SwitchColor($COLOR_RED)) ; 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($COLOR_LIGHTBLUE)) ; RGB to BGR _WinAPI_SetBkMode($tItem.HDC, $OPAQUE) _WinAPI_SetTextColor($tItem.HDC, _WinAPI_SwitchColor($COLOR_BLUE)) ; 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