display sorting triangle in ListView column header

How can I display in a ListView column header a triangle that shows after which column are sorted the items, and in which direction (like in the Microsoft Internet Mail and News)?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

erajojConnect With a Mentor Commented:
You could do something like this:

  ...ComCtrls, Commctrl;

  MyBMP : TBitmap;
  hditem: THDItem;

  MyBMP := TBitmap.Create;
  with MyBMP do begin
    Canvas.Brush.Color := clBtnFace;
    Width  := 10;
    Height := 10;
// down...
//  up...
//  Canvas.Polyline([Point(0,8),Point(4,0),Point(8,8),Point(0,8)]);


  hditem.Mask := HDI_FORMAT;
  Header_GetItem( GetDlgItem( ListView1.Handle, 0 ), 1, hditem );
  hditem.Mask := HDI_BITMAP or HDI_FORMAT;
  hditem.fmt  := hditem.fmt or HDF_BITMAP;
  hditem.hbm := MyBMP.Handle;
  Header_SetItem( GetDlgItem( ListView1.Handle, 0 ), 1, hditem );

/// John

Did you check it? It doesn't seem to work.
biroadamAuthor Commented:
 Thank you, it was a good answer.

  I have two further questions:

  1. How can I move the bitmap on the RIGHT side of the column header’s caption (the bitmap generated by your code is on the left side)?

  2. How can I resolve the transparency problem for this bitmap? I must have a triangle on a clButtonFace background, so I have two choises: A. making a procedure which calls the CreateGrayMappedBmp function every time the system colors changes, or B. I have a transparent color.

  I couldn’t use the solution B because setting my bitmap’s Transparency, TransparentColor and TransparentMode properties, the transparency didn’t work on the column header.
Does it work on NT4?
Does it work when the listview is not on the main form?

If yes, can you please send me the sample code?  ronith@cmr.co.il

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.