By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

Add an arrow onto listView header column

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Li Pang" <Li****@discussions.microsoft.com> schrieb:
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?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #2

P: n/a
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.
"Herfried K. Wagner [MVP]" wrote:
"Li Pang" <Li****@discussions.microsoft.com> schrieb:
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?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.