Icon In ListView Header .Net
-
I have been trying to get my listview to show an icon on the right side of the header if that column has been clicked. So far I have had almost no luck. Any links to one would be great. Showing code would be good too. I know I had found one once, but I can not find it again. Thanks
-
I have been trying to get my listview to show an icon on the right side of the header if that column has been clicked. So far I have had almost no luck. Any links to one would be great. Showing code would be good too. I know I had found one once, but I can not find it again. Thanks
I have this code that I found, but I keep getting a Nullreference error. Declarations
Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hwnd As IntPtr, _ ByVal wMsg As Integer, _ ByVal wParam As Integer, _ ByVal lParam As HD_ITEM) As Long Const LVM_FIRST = &H1000 Const LVM_GETHEADER = (LVM_FIRST + 31) Const HDI_BITMAP = &H10 Const HDI_IMAGE = &H20 Const HDI_FORMAT = &H4 Private Const HDI_TEXT = &H2 Private Const HDF_BITMAP_ON_RIGHT = &H1000 Private Const HDF_BITMAP = &H2000 Private Const HDF_IMAGE = &H800 Private Const HDF_STRING = &H4000 Private Const HDM_FIRST = &H1200 Private Const HDM_SETITEM = (HDM_FIRST + 4) Private Const HDM_SETIMAGELIST = (HDM_FIRST + 8) Private Const HDM_GETIMAGELIST = (HDM_FIRST + 9) Private Structure HD_ITEM Dim mask As Integer Dim cxy As Integer Dim pszText As String Dim hbm As Integer Dim cchTextMax As Integer Dim fmt As Integer Dim lParam As Integer Dim iImage As Integer Dim iOrder As Integer End Structure
Dim hHeader As IntPtr = ShellDll.SendMessage(lstView.Handle, Win32.WindowsMessages.LVM_GETHEADER, 0, 0) Dim lvImage As IntPtr = ShellDll.SendMessage(hHeader, Win32.WindowsMessages.HDM_SETIMAGELIST, 0, CInt(Me.imgArrows.Handle.ToInt32)) Dim lret As IntPtr For i As Integer = 0 To lstView.Columns.Count - 1 'Use the LVM_SETCOLUMN message to set the column's image index. Dim HD As New HD_ITEM Dim pblnAlignRight As Boolean With HD .mask = HDI_IMAGE Or HDI_FORMAT .pszText = lstView.Columns(i).Text End With If lstView.Columns(i).TextAlign = HorizontalAlignment.Right Then pblnAlignRight = True Else pblnAlignRight = False End If If i = ColumnIndex Then With HD .fmt = HDF_STRING Or HDF_IMAGE Or HDF_BITMAP_ON_RIGHT .iImage = IconIndex End With Else HD.fmt = HDF_STRING End If SendMessage(hHeader, HDM_SETITEM, i, HD)'error occurs here Next