Add an arrow onto listView header column

G

Guest

Hi,

I used some code to add an arrow icon onto a listview header column for the
sorting purpose. However, after the icon added, the TextAlign of the column
becomes "left", if I enforced TextAlign = right, the icon disppeared. Is
somebody has a solution?

Thanks
 
H

Herfried K. Wagner [MVP]

Li Pang said:
I used some code to add an arrow icon onto a listview header column for
the
sorting purpose. However, after the icon added, the TextAlign of the
column
becomes "left", if I enforced TextAlign = right, the icon disppeared. Is
somebody has a solution?

How did you add the icon?
 
G

Guest

Hi,

Here the function I used to add the arrow onto the column header:

Private Sub ShowHeaderIcon(ByVal colNo As Integer, ByVal imgIconNo As
Integer, ByVal showImage As Boolean)

Dim hwnd As IntPtr
Dim lret As IntPtr
Dim i As Integer
Dim col As LVCOLUMN
'Assign the ImageList to the header control.
'The header control includes all columns.
'Get a handle to the header control.
hwnd = SendMessage(Me.ListView1.Handle, LVM_GETHEADER, 0, 0)

lret = SendMessage(hwnd, HDM_SETIMAGELIST, 0,
(ImageList1.Handle).ToInt32)
col.mask = LVCF_FMT Or LVCF_IMAGE
'col.fmt = LVCFMT_IMAGE Or LVCFMT_BITMAP_ON_RIGHT
'The image to use from the Image List.
'col.iImage = iconImage ' first image
col.cchTextMax = 0
col.cx = 0
col.iOrder = 0
col.iSubItem = 0
col.pszText = IntPtr.op_Explicit(0)

If showImage Then
'.fmt = HDF_STRING Or HDF_IMAGE Or HDF_BITMAP_ON_RIGHT
col.fmt = LVCFMT_STRING Or LVCFMT_IMAGE Or LVCFMT_BITMAP_ON_RIGHT
'.iImage = imgIconNo
col.iImage = imgIconNo 'iconImage ' first image
Else
'.fmt = HDF_STRING
col.fmt = LVCFMT_STRING
End If
'Send the LVM_SETCOLUMN message.
'The column to which you are assigning the image is defined in the
third parameter.
lret = SendMessage(Me.ListView1.Handle, LVM_SETCOLUMN, colNo, col)

End Sub

As you can see the icon is added ate the right of the header title. It works
fine when the column textalign = left, but got the trunble when the
textalign= right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top