Using icon in a ListView ColumnHeader (VB5.0) 
Author Message
 Using icon in a ListView ColumnHeader (VB5.0)

Hi,
I am using the piece of source code downloaded from <Planet Source
Code> which puts some icon on the ColumnHeader of a ListView whenever
it has been clicked by user.

This works find and i can resort/reorder the ListView depends on the
ColumnHeader which gets a ColumnClick event.
Using SendMessage API call lets me even to put a suitable icon
Ascending/Descending at the ColumnHeader.

The problem is After putting the icon all columns are aligned in a way
which differs from default settings.
Almost all columns are presented as Center-Alligned however using some
button to ask the properties of listView.ColumnHeader says that all
alignment settings are still OK.

Does anybody knows how this come???
How could a column be left alligned and it be positioned at right
side???

Thanks in advance,
N. Silakhori
THIS IS MY CODE:
====================================
' Following API calls and declarations are meant for building icons
' in the ListView header buttons
Public Declare Function SendMessage Lib "User32" _
                                Alias "SendMessageA" _
                                (ByVal hWnd As Long, _
                                ByVal Msg As Long, _
                                ByVal wParam As Long, _
                                lParam As Any) As Long

Public Declare Function SendMessageLong Lib "User32" _
                                Alias "SendMessageA" _
                                (ByVal hWnd As Long, _
                                ByVal wMsg As Long, _
                                ByVal wParam As Long, _
                                ByVal lParam As Long) As Long

Public Declare Function SendMessageAny Lib "User32" _
                                Alias "SendMessageA" _
                                (ByVal hWnd As Long, _
                                ByVal wMsg As Long, _
                                ByVal wParam As Long, _
                                lParam As Any) As Long

Global Const LISTVIEW_BUTTON = 9
Public Const LVM_FIRST = &H1000
Public Const LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54
Public Const LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55
Public Const LVS_EX_FULLROWSELECT = &H20
Public Const LVM_GETHEADER = (LVM_FIRST + 31)
Public Const HDI_IMAGE = &H20
Public Const HDI_FORMAT = &H4
Public Const HDF_LEFT = 0
Public Const HDF_IMAGE = &H800
Public Const HDF_BITMAP_ON_LEFT = &H0
Public Const HDF_BITMAP_ON_RIGHT = &H1000
Public Const HDF_STRING = &H4000
Public Const HDM_FIRST = &H1200
Public Const HDM_SETITEM = (HDM_FIRST + 4)

Public 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

PROCEDURES:
=================================
Private Sub lvListView_ColumnClick(ByVal ColumnHeader As
ComctlLib.ColumnHeader)
Dim i As Long
Dim iconAlignment As AlignConstants
Static sOrder
   sOrder = Not sOrder
   'Use default sorting to sort the items in the list
   With lvListView
      .SortKey = ColumnHeader.Index - 1
      .SortOrder = Abs(sOrder)
      .Sorted = True
      If ColumnHeader.Alignment = lvwColumnLeft Or
ColumnHeader.Alignment = lvwColumnCenter Then
         iconAlignment = HDF_BITMAP_ON_RIGHT
      ElseIf ColumnHeader.Alignment = lvwColumnRight Then
         iconAlignment = HDF_BITMAP_ON_LEFT
      End If
      MsgBox "iconAlignment = " & str$(ColumnHeader.Alignment)
      'clear the image from the header not currently
      'sorted, and update the header clicked
      For i = 0 To .ColumnHeaders.Count - 1
         'if this is the index of the header clicked
         If i = .SortKey Then
            ShowHeaderIcon .hWnd, .SortKey, .SortOrder, HDF_IMAGE,
ColumnHeader.Alignment
            'MsgBox lvListView.ColumnHeaders(i + 1).Alignment,
vbInformation, lvListView.ColumnHeaders(i + 1).Text
         Else
            ShowHeaderIcon lvListView.hWnd, i, 0, 0,
ColumnHeader.Alignment
            'MsgBox lvListView.ColumnHeaders(i + 1).Alignment,
vbExclamation, lvListView.ColumnHeaders(i + 1).Text
         End If
      Next i
   End With
End Sub

Public Sub ShowHeaderIcon(lngHwnd As Long, colNo As Long, imgIconNo As
Long, _
                                                            showImage
As Long, _
                                                            ColAllign
As AlignConstants)
Dim r As Long
Dim hHeader As Long
Dim HD As HD_ITEM

   hHeader = SendMessageLong(lngHwnd, LVM_GETHEADER, 0, 0)
   With HD
      .mask = HDI_IMAGE Or HDI_FORMAT
      If ColAllign = lvwColumnLeft Then
        .fmt = HDF_LEFT Or HDF_STRING Or HDF_BITMAP_ON_RIGHT Or
showImage
      Else
        .fmt = HDF_LEFT Or HDF_STRING Or HDF_BITMAP_ON_LEFT Or
showImage
      End If
      If showImage Then .iImage = imgIconNo
   End With     'modify the header
   r = SendMessageAny(hHeader, HDM_SETITEM, colNo, HD)
   'lvListView.ColumnHeaders(2).Alignment = lvwColumnRight
End Sub



Sat, 17 Mar 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Using icons in ListView ColumnHeader

2. Using Icon in the ListView ColumnHeader

3. VB5: Problems with Listview ColumnHeaders at design-time (using Service Pack 1)

4. VB5: Problems with Listview ColumnHeaders at design-time (using Service Pack 1)

5. How insert icon to Listview ColumnHeader?

6. ListView - ColumnHeader icon

7. ListView: Column Text becomes Left-Aligned when ColumnHeader Icon is changed in Code

8. listview columnheader icon alignment

9. Listview ColumnHeader Icon

10. ListView: Column Text becomes Left-Aligned when ColumnHeader Icon is changed in Code

11. listview columnheader icons

12. Listview ColumnHeader Icons

 

 
Powered by phpBB® Forum Software