# Function Reference

# _GUICtrlHeader_InsertItem

Inserts a new header item

#include <GuiHeader.au3>
_GUICtrlHeader_InsertItem ( $hWnd, $iIndex, $sText [, $iWidth = 50 [, $iAlign = 0 [, $iImage = -1 [, $bOnRight = False]]]] )

## Parameters

$hWnd | Handle to the control
$iIndex | Index of the item after which the new item is to be inserted. The new item is inserted at the end of the control if index is greater than or equal to the number of items in the control. If index is zero, the new item is inserted at the beginning of the control.
$sText | Item text. See remark.
$iWidth | [optional] Item width
$iAlign | [optional] Text alignment: 0 - Text is left-aligned 1 - Text is right-aligned 2 - Text is centered
$iImage | [optional] 0-based index of an image within the image list
$bOnRight | [optional] If True, the column image appears to the right of text

## Return Value

Success: | the index of the new item.
Failure: | -1.

## Remarks

If a notification callback is needed, you have to specify $sText = -1 (LPSTR_TEXTCALLBACK).

## Related

_GUICtrlHeader_AddItem, _GUICtrlHeader_DeleteItem

## Example

### Example 1

    #include "Extras\HelpFileInternals.au3"

    #include <GUIConstantsEx.au3>
    #include <GuiHeader.au3>
    #include <GuiImageList.au3>
    #include <WinAPIGdi.au3>

    Example()

    Func Example()
        ; Create GUI
        Local $hGUI = GUICreate("Header Insert Item (v" & @AutoItVersion & ")", 450, 300, 100, 100)
        Local $hHeader = _GUICtrlHeader_Create($hGUI)
        _MemoCreate(2, 52, 444, 220)

    ;~  _GUICtrlHeader_SetUnicodeFormat($hHeader, True)

        GUISetState(@SW_SHOW)

        ; Create an image list with images
        Local $hImage = _GUIImageList_Create(11, 11)
        _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap($hGUI, 0xFF0000, 11, 11))
        _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap($hGUI, 0x00FF00, 11, 11))
        _GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap($hGUI, 0x0000FF, 11, 11))
        _GUICtrlHeader_SetImageList($hHeader, $hImage)

        ; Add columns
        _GUICtrlHeader_AddItem($hHeader, "Column 0", 90, 0, 0)
        _GUICtrlHeader_AddItem($hHeader, "Column 1", 90, 0, 1)
        _GUICtrlHeader_AddItem($hHeader, "Column 2", 90, 0, 2)
        _GUICtrlHeader_AddItem($hHeader, "Column 3", 90)

        ; Insert new column
        _GUICtrlHeader_InsertItem($hHeader, 1, "Column X", 90, 2, 0)

        _MemoMsgBoxStatus("", -1, $hGUI) ; no more action, wait GUI for closing

    EndFunc   ;==>Example

### Example 2 : Header Insert Item to an External process

    #include "Extras\HelpFileInternals.au3"

    #include <GuiHeader.au3>

    Example()

    Func Example()
        Local $sFromTo
        Local $hWin = _MemoRunAU3OutProcess($sFromTo, False) ; OK if run in different Mode

        Local $hHeader = _MemoCreateOutProcess($hWin, "SysHeader32", 0, $sFromTo)

        _GUICtrlHeader_InsertItem($hHeader, 2, "<<<Column Y", 100, 2, 2)
        _MemoWrite("Column #2 changed to <<<Column Y")

        _MemoMsgBoxStatus("", -1, $hWin) ; no more action, wait GUI for closing

    EndFunc   ;==>Example