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

Arrow on a ListView Column Header

P: n/a
Dan
Hi,

I would like my list view controls column headers to display a "down arrow /
triangle" to indicate by which column they are sorted.

I don't want the ListView to actually sort any data as the sorting is done
elsewhere, I just want the arrow!

Thanks in advance

Dan
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> I would like my list view controls column headers to display a "down arrow
/
triangle" to indicate by which column they are sorted.


below a code snippet taken from my source.
since I do not want to include much code here, you'll have to work out
missing Win32 declarations by yourself.

regards,
Wiktor Zychla

// ListView variable is global here
public void SetHeaderBitmap( int iColumn, Bitmap bBitmap )
{
// win32 structure
HDITEM h = new HDITEM();
h.mask = (int)HeaderItemFlags.HDI_BITMAP |
(int)HeaderItemFlags.HDI_FORMAT;
h.hbm = bBitmap.GetHbitmap();
h.fmt = (int)HeaderItemFormat.HDF_LEFT |
(int)HeaderItemFormat.HDF_STRING |
(int)HeaderItemFormat.HDF_BITMAP ;

// take a pointer to header control
IntPtr hHeader = (IntPtr)WindowsAPI.SendMessage( this.lstLista.Handle,
(int)ListViewMessages.LVM_GETHEADER, 0, 0 );
// set the header icon
WindowsAPI.SendMessage( hHeader, (int)HeaderControlMessages.HDM_SETITEM,
iColumn, ref h );
}
Nov 16 '05 #2

P: n/a
The trick is to change the column text value when sorting by adding 3
spaces
and the Unicode characters for the small black Up and Down triangles.
Strip
them off when changing columns.

Sample code for lurkers:
Protected Overrides Sub dvDisplay_ColumnClick(ByVal sender As Object,
ByVal
e As System.Windows.Forms.ColumnClickEventArgs)

'remove sort icon from old column.

If SortColumn <> -1 Then

lv.Columns.Item(SortColumn).Text =
lv.Columns.Item(SortColumn).Text.TrimEnd(Chr(32), Chr(32), Chr(32),
ChrW(&H25B2), ChrW(&H25BC))

End If

If e.Column <> SortColumn Then

SortColumn = e.Column

mSortDirection = "ASC"

'add down icon

lv.Columns.Item(SortColumn).Text &= " " & ChrW(&H25B2)

Else

If mSortDirection = "ASC" Then

mSortDirection = "DESC"

'do the sort

'add down icon

lv.Columns.Item(SortColumn).Text &= " " & ChrW(&H25BC)

Else

mSortDirection = "ASC"

'do the sort

'add up icon

lv.Columns.Item(SortColumn).Text &= " " & ChrW(&H25B2)

End If

End If

End Sub
On Tue, 25 May 2004 09:24:27 +0100, "Dan"
<dan.parker@_nospam_pro-bel.com> wrote:
Hi,

I would like my list view controls column headers to display a "down arrow /
triangle" to indicate by which column they are sorted.

I don't want the ListView to actually sort any data as the sorting is done
elsewhere, I just want the arrow!

Thanks in advance

Dan


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.