Icons in List View Columns 
Author Message
 Icons in List View Columns

I have a list view which has multiple columns and is sortable by most of
them, by clicking on the column headers.  Is there a way to place an icon on
the column header of the list view to indicate that the list is sorted by
that column?  (Much like the arrows in Microsoft Outlook)


Sun, 08 Jul 2001 03:00:00 GMT  
 Icons in List View Columns

Quote:

> I have a list view which has multiple columns and is sortable by most of
> them, by clicking on the column headers.  Is there a way to place an icon on
> the column header of the list view to indicate that the list is sorted by
> that column?  (Much like the arrows in Microsoft Outlook)

Yes.

http://www.mvps.org/vbnet/code/comctl/lvheaderimage.htm

--



Mon, 09 Jul 2001 03:00:00 GMT  
 Icons in List View Columns
put this code on BAS module
Public Declare Function SendMessageLong Lib "user32" Alias
"SendMessageA" _
   (ByVal hwnd As Long, _
    ByVal msg 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 msg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long

Public Const LVM_FIRST = &H1000
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_STRING = &H4000
Public Const HDM_FIRST = &H1200
Public Const HDM_SETITEM = (HDM_FIRST + 4)
Public Const HDF_IMAGE = &H800
Public Const HDF_BITMAP_ON_RIGHT = &H1000

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

Public Sub ShowHeaderIcon(colNo As Long, imgIconNo As Long, _
                          justify As Long, showImage As Long)

   Dim r As Long
   Dim hHeader As Long
   Dim HD As HD_ITEM

  'get a handle to the listview header component
   hHeader = SendMessageLong(testform.lvwSpecial.hwnd, LVM_GETHEADER, 0,
0)
  'set up the required structure members
   With HD
      .mask = HDI_IMAGE Or HDI_FORMAT
      .fmt = HDF_LEFT Or HDF_STRING Or justify Or showImage
      .pszText = testform.lvwSpecial.ColumnHeaders(colNo + 1).Text
      If showImage Then .iImage = imgIconNo 'based 0 index
   End With

  'modify the header
   r = SendMessageAny(hHeader, HDM_SETITEM, colNo, HD)

End Sub

Form code:

Private Sub lvwSpecial_ColumnClick(ByVal ColumnHeader As
ComctlLib.ColumnHeader)    
    Dim i As Long
    Static sOrder  
   sOrder = Not sOrder

  'Use default sorting to sort the items in the list
   lvwSpecial.SortKey = ColumnHeader.Index - 1
   lvwSpecial.SortOrder = Abs(sOrder)
   lvwSpecial.Sorted = True

  'clear the image from the header not currently
  'sorted, and update the header clicked
   For i = 0 To lvwSpecial.ColumnHeaders.Count - 1

     'if this is the index of the header clicked
      If i = lvwSpecial.SortKey Then
      'lvwSpecial.SortOrder has tow values 0,1 correcponding to order
imagelist
      'if you want display only one picture, replace it with a number in
imagelist
            ShowHeaderIcon lvwSpecial.SortKey, _
                           lvwSpecial.SortOrder, _
                           HDF_BITMAP_ON_RIGHT, _
                           HDF_IMAGE

      Else: ShowHeaderIcon i, 0, 0, 0
      End If
   Next
End Sub

Phuong that ton
OCS programmer

Quote:
> ----------

> Posted At:         21 January 1999 06:00
> Posted To:         misc
> Conversation:      Icons in List View Columns
> Subject:   Icons in List View Columns

> I have a list view which has multiple columns and is sortable by most
> of
> them, by clicking on the column headers.  Is there a way to place an
> icon on
> the column header of the list view to indicate that the list is sorted
> by
> that column?  (Much like the arrows in Microsoft Outlook)



Tue, 10 Jul 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Display Bitmaps in Sub Items and column Headers of List View During Report View

2. List View Column - - Possible items in a Single Column

3. List View Top Item in Large Icon View

4. Tree View & List View Icons

5. Listview v.6.0 column size in small icon view

6. Listview small icon view column size

7. Formatting Column in List View

8. List View Columns

9. Sorting the content of list view on clicking column headers

10. List View Column Headers

11. List View Column Sizes

12. Column width of List view

 

 
Powered by phpBB® Forum Software