473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Arrow on a ListView Column Header

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
2 10895
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: andrewcw | last post by:
The clcik event on the ListView control seems to trigger off the item level ( the first column ). I would like to be able to trap the click event on a particular subitem ( a specific column's row...
3
by: Steve | last post by:
I have windows form with ListView control. The ListView control has few columns which user can sort by clicking the column header. I want the column header have the small triangle indicator of...
2
by: Just Me | last post by:
Listview is Docked=Fill I set all column widths to -2 and it works as expected if the listview needs to be too wide for the window. That is, I get an H-scrollbar and the columns are the correct...
2
by: Li Pang | last post by:
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...
12
by: J L | last post by:
When I fill a listview, I resize the columns to fit the data. I need to know if the data will fit vertically or if there will be a vertical scroll bar. I need to know this so I can allow for it on...
2
by: Steve Randall | last post by:
I have a listview control containing a number of columns. When I populate the listview columns with data I want to size each column according to the following rules: 1. If the width of the data...
0
by: Reddy4All | last post by:
Hi- Is there any possiblity to make Datagrid control (Winforms) column header sort arrow more prominent in .net 2003. In Windows forms Datagrid control, when user click on the column header, default...
0
by: Reddy4All | last post by:
Hi- Is there any possiblity to make Datagrid control (Winforms) column header sort arrow more prominent in .net 2003. In Windows forms Datagrid control, when user click on the column header, default...
0
by: bharathreddy | last post by:
Hi All, I am using a listview control in my usercontrol so that it can be used in more than one form. This user control has one column extraw, so i want to make it invisible depending on the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.