CHeaderCtrl::InsertItem

Inserts a new item into a header control at the specified index.

int InsertItem( 
   int nPos, 
   HDITEM* phdi  
);

Parameters

  • nPos
    The zero-based index of the item to be inserted. If the value is zero, the item is inserted at the beginning of the header control. If the value is greater than the maximum value, the item is inserted at the end of the header control.

  • phdi
    Pointer to an HDITEM structure that contains information about the item to be inserted.

Return Value

Index of the new item if successful; otherwise – 1.

Example

CString str;
HDITEM  hdi;

hdi.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT | HDI_IMAGE;
hdi.cxy = 100; // Make all columns 100 pixels wide.
hdi.fmt = HDF_STRING | HDF_CENTER;

// Insert 6 columns in the header control. 
for (int i=0; i < 6; i++)
{
   str.Format(TEXT("column %d"), i);
   hdi.pszText = str.GetBuffer(0);
   hdi.iImage = i % 3;

   m_myHeaderCtrl.InsertItem(i, &hdi);
}

Requirements

Header: afxcmn.h

See Also

Reference

CHeaderCtrl Class

Hierarchy Chart

CHeaderCtrl::DeleteItem

CHeaderCtrl::GetItem