This is a snipped of the code I use. My icons are in a ImageList (imgList) control.
You can find all the API definitions in the APIViewer. Sorry if did not post the whole thing, it is just a big UserControl that I designed. Call this code anytime the sorting mode changes.
Marco
Dim hColHeader As Long
Dim hItem As HDITEM
Dim k As Long
Dim bAlignRight As Boolean
hColHeader = SendMessage(lstData.hwnd, LVM_GETHEADER, 0, 0)
SendMessage hColHeader, HDM_SETIMAGELIST, 0, ByVal imgList.hImageList
For k = 0 To lstData.ColumnHeaders.Count - 1
bAlignRight = (lstData.ColumnHeaders.Item(k + 1).Alignment = lvwColumnRight)
hItem.mask = HDI_FORMAT Or HDI_IMAGE
If bAlignRight Then
hItem.fmt = HDF_STRING Or HDF_RIGHT
Else
hItem.fmt = HDF_STRING
End If
If k = lstData.SortKey Then
hItem.fmt = hItem.fmt Or HDF_IMAGE
If bAlignRight Then hItem.fmt = hItem.fmt Or HDF_BITMAP_ON_RIGHT
End If
hItem.iImage = _
imgList.ListImages(IIf(lstData.SortOrder, cAscending, cDescending)).index - 1
SendMessage hColHeader, HDM_SETITEM, k, hItem
Next
|