How to add a glyph to a column on a TListView.

Posted on 2003-10-23
Last Modified: 2013-12-02
How do I add a Glyph to a Column on a TListView like windows explorer?  I want to do this to a TListview, preferably with some an API call.
I wish to add the Up/Down glyphs that you see in windows explorer when you sort a column.
Question by:Colin_Dawson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
LVL 26

Accepted Solution

Russell Libby earned 125 total points
ID: 9611307

Assign an ImageList to the listview's SmallImages property, then set the columns ImageIndex property through the object inspector, or via code:



Hope this is what your after, if not perhaps you could specify further


Author Comment

ID: 9612697
Close, but no cigar.  The image that I want is on the right hand side of the text.  Load Windows explorer and set the contents of a folder to "Details".  Now click on the filename header button.  You'll see an arrow pointing down.  Click again and the arrow will point up - and the list will be re-sorted.   I know how to make the list sort, so that's not a problem.   What I'm after is putting in the visual style, so that my tree view can behave more like the one in windows explorer.

The reason that I'm being so picky about this is that I want my Listview to be compatible with the Windows Themes in XP.

Author Comment

ID: 9612723
Ok, I've done a little digging about on the net, and found the windows message that controlls the headers.  The message is  HDM_SETITEM.   I can see that the Sort items look new with Version 6 of Comctrl32. I'm now looking at how to implement it.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 9612752
OK, Getting closer still.

It doesn't mention that you need to add CommCtrl to your uses clause.    Now all I need to do is add the extra bit for the windows XP theme.

Author Comment

ID: 9612782
Getting even closer now.  Got the icon working with XP, here's my variation on the code.  Notice that I needed to declare a couple of new Constants, these are missing from Delphi's API headers.

  Procedure SetColumnImage(List: TListView; Column, Image: Integer; ShowImage: Boolean);
    HDF_SORTDOWN = $200;
    HDF_SORTUP = $400;
   Align,hHeader: integer;

   hHeader := SendMessage(List.Handle, LVM_GETHEADER, 0, 0);
   with HD do
       case List.Columns[Column].Alignment of
         taLeftJustify:  Align := HDF_LEFT;
         taCenter:       Align := HDF_CENTER;
         taRightJustify: Align := HDF_RIGHT;
         Align := HDF_LEFT;

       mask := HDI_IMAGE or HDI_FORMAT;

       pszText := PChar(List.Columns[Column].Caption);

       if ShowImage then
         fmt := HDF_STRING or Align;

       If Image = 0
       Then fmt := fmt or HDF_SORTDOWN
       Else fmt := fmt or HDF_SORTUP;

       iImage := Image;

   SendMessage(hHeader, HDM_SETITEM, Column, Integer(@HD));

Now for the icing on the cake, I need to get the column itself to highligh in the way that windows explorer does in Windows XP.

Author Comment

ID: 9613094
Having taken a little closer look I think it's only fair to ask about putting the shading onto the column as a seperate question.  Using the Columns.ImageIndex for the bitmap that I wanted was in the right direction for the correct solution, but as you can plainly see it's a hell of a long way short of the right answer.

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question