I'm trying to put icons in the header of my ListView. All the .net
posts I found refer to an example on thecodeproject which is no longer
there (part of commercial package now).
I converted the code I used in VB6 which all appears to run ok but
doesn't actually create the images ever. These are generic functions
to set the images for any listview.
Please help,
Thanks,
Sam
' Win32 is a custom class that has the necessary Win32 constants,
structures, and function declarations
Public Sub ListViewSetHeaderImages(ByVal lvw As ListView, ByVal
images As ImageList)
Dim headerHandle As IntPtr = Win32.SendMessage(lvw.Handle,
Win32.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero)
Win32.SendMessage(headerHandle, Win32.HDM_SETIMAGELIST,
IntPtr.Zero, images.Handle)
End Sub
Public Sub ListViewSetHeaderIcon(ByVal lvw As ListView, ByVal
headerText As String, ByVal columnIndex As Integer, ByVal imageIndex
As Integer)
Dim headerHandle As IntPtr
Dim HD As New Win32.HDITEM
headerHandle = Win32.SendMessage(lvw.Handle,
Win32.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero)
With HD
.mask = Win32.HDI_IMAGE Or Win32.HDI_FORMAT
.pszText = headerText
.fmt = Win32.HDF_STRING Or Win32.HDF_IMAGE Or
Win32.HDF_BITMAP_ON_RIGHT
.iImage = imageIndex
End With
Win32.SendMessage(headerHandle, Win32.HDM_SETITEM, columnIndex,
HD)
End Sub
Private Sub ListViewRemoveHeaderIcon(ByVal lvw As ListView, ByVal
columnIndex As Integer)
Dim headerHandle As IntPtr
Dim hdHeader As New Win32.HDITEM
headerHandle = Win32.SendMessage(lvw.Handle,
Win32.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero)
hdHeader.mask = Win32.HDI_FORMAT
hdHeader.fmt = hdHeader.fmt Or Win32.HDF_STRING
Win32.SendMessage(headerHandle, Win32.HDM_SETITEM, columnIndex,
hdHeader)
End Sub