Clciking listview header with icon loses right justify
Hello peeps,
I have a listview with an ascending/descending icon available on each header which shows the sort order of the column.
My problem is that my numeric field (file size) is right justified when i launch the program and populate the listview but when i click on this header it adds the icon showing the currnt sort order but the column reverts to left justify. Heres my code...what do i do to make it right justify again? Thanks
VB Code:
Private Const HDI_BITMAP = &H10
Private Const HDI_IMAGE = &H20
Private 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 Type HD_ITEM
mask As Long
cxy As Long
pszText As String
hbm As Long
cchTextMax As Long
fmt As Long
lParam As Long
iImage As Long
iOrder As Long
End Type
Public Sub ShowHeaderIcon(colNo As Long, imgIconNo As Long, showImage As Long, LView As Listview)
Dim hHeader As Long
Dim HD As HD_ITEM
'get a handle to the listview header component
hHeader = SendMessage(LView.hwnd, LVM_GETHEADER, 0, ByVal 0)
'set up the required structure members
With HD
.mask = HDI_IMAGE Or HDI_FORMAT
.pszText = LView.ColumnHeaders(colNo + 1).Text
If showImage Then
If colNo = 1 And LView.Name = "MatchFiles" Then
.fmt = HDF_STRING Or HDF_IMAGE
Else
.fmt = HDF_STRING Or HDF_IMAGE Or HDF_BITMAP_ON_RIGHT
End If
.iImage = imgIconNo
Else
.fmt = HDF_STRING
End If
End With
'modify the header
Call SendMessage(hHeader, HDM_SETITEM, colNo, HD)
End Sub