Colin_Dawson
asked on
How to add a glyph to a column on a TListView.
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.
I wish to add the Up/Down glyphs that you see in windows explorer when you sort a column.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
OK, Getting closer still.
http://www.delphipages.com/tips/thread.cfm?ID=74
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.
http://www.delphipages.com/tips/thread.cfm?ID=74
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.
ASKER
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);
Const
HDF_SORTDOWN = $200;
HDF_SORTUP = $400;
var
Align,hHeader: integer;
HD: HD_ITEM;
begin
hHeader := SendMessage(List.Handle, LVM_GETHEADER, 0, 0);
with HD do
begin
case List.Columns[Column].Align ment of
taLeftJustify: Align := HDF_LEFT;
taCenter: Align := HDF_CENTER;
taRightJustify: Align := HDF_RIGHT;
else
Align := HDF_LEFT;
end;
mask := HDI_IMAGE or HDI_FORMAT;
pszText := PChar(List.Columns[Column] .Caption);
if ShowImage then
fmt := HDF_STRING or HDF_IMAGE or HDF_BITMAP_ON_RIGHT
else
fmt := HDF_STRING or Align;
If Image = 0
Then fmt := fmt or HDF_SORTDOWN
Else fmt := fmt or HDF_SORTUP;
iImage := Image;
end;
SendMessage(hHeader, HDM_SETITEM, Column, Integer(@HD));
end;
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.
Procedure SetColumnImage(List: TListView; Column, Image: Integer; ShowImage: Boolean);
Const
HDF_SORTDOWN = $200;
HDF_SORTUP = $400;
var
Align,hHeader: integer;
HD: HD_ITEM;
begin
hHeader := SendMessage(List.Handle, LVM_GETHEADER, 0, 0);
with HD do
begin
case List.Columns[Column].Align
taLeftJustify: Align := HDF_LEFT;
taCenter: Align := HDF_CENTER;
taRightJustify: Align := HDF_RIGHT;
else
Align := HDF_LEFT;
end;
mask := HDI_IMAGE or HDI_FORMAT;
pszText := PChar(List.Columns[Column]
if ShowImage then
fmt := HDF_STRING or HDF_IMAGE or HDF_BITMAP_ON_RIGHT
else
fmt := HDF_STRING or Align;
If Image = 0
Then fmt := fmt or HDF_SORTDOWN
Else fmt := fmt or HDF_SORTUP;
iImage := Image;
end;
SendMessage(hHeader, HDM_SETITEM, Column, Integer(@HD));
end;
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.
ASKER
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.
ASKER
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.